• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lucaslorentz / auto-compute / 12972048738

26 Jan 2025 06:09AM UTC coverage: 83.217% (-1.2%) from 84.441%
12972048738

push

github

lucaslorentz
Add consistency checks with time filter

9 of 41 new or added lines in 9 files covered. (21.95%)

1790 of 2151 relevant lines covered (83.22%)

431.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.0
/src/LLL.AutoCompute.EFCore/Extensions/EntityTypeBuilderExtensions.cs
1
using System.Linq.Expressions;
2
using LLL.AutoCompute.EFCore.Metadata.Internal;
3
using Microsoft.EntityFrameworkCore.Metadata.Builders;
4

5
namespace LLL.AutoCompute.EFCore;
6

7
public static class EntityTypeBuilderExtensions
8
{
9
    public static PropertyBuilder<TProperty> ComputedProperty<TEntity, TProperty>(
10
        this EntityTypeBuilder<TEntity> entityTypeBuilder,
11
        Expression<Func<TEntity, TProperty>> propertyExpression,
12
        Expression<Func<TEntity, TProperty>> computedExpression,
13
        ChangeCalculationSelector<TProperty, TProperty>? calculationSelector = null)
14
        where TEntity : class
15
    {
16
        return entityTypeBuilder.Property(propertyExpression)
154✔
17
            .AutoCompute(computedExpression, calculationSelector);
154✔
18
    }
19

20
    public static NavigationBuilder<TEntity, TProperty> ComputedNavigation<TEntity, TProperty>(
21
        this EntityTypeBuilder<TEntity> entityTypeBuilder,
22
        Expression<Func<TEntity, TProperty>> navigationExpression,
23
        Expression<Func<TEntity, TProperty>> computedExpression,
24
        ChangeCalculationSelector<TProperty, TProperty>? calculationSelector = null,
25
        Action<IComputedNavigationBuilder<TEntity, TProperty>>? configure = null)
26
        where TEntity : class
27
        where TProperty : class
28
    {
29
        return entityTypeBuilder.Navigation(navigationExpression!)
2✔
30
            .AutoCompute(computedExpression, calculationSelector, configure);
2✔
31
    }
32

33
    public static void ComputedObserver<TEntity, TValue, TChange>(
34
        this EntityTypeBuilder<TEntity> entityTypeBuilder,
35
        Expression<Func<TEntity, TValue>> computedExpression,
36
        Expression<Func<TEntity, bool>>? filterExpression,
37
        ChangeCalculationSelector<TValue, TChange> calculationSelector,
38
        Func<TEntity, TChange?, Task> callback)
39
        where TEntity : class
40
    {
41
        entityTypeBuilder
12✔
42
            .ComputedObserver(
12✔
43
                computedExpression,
12✔
44
                filterExpression,
12✔
45
                calculationSelector,
12✔
46
                async (ComputedChangeEventData<TEntity, TChange> eventData) =>
12✔
47
                {
12✔
48
                    foreach (var (entity, change) in eventData.Changes)
64✔
49
                    {
12✔
50
                        await callback(entity, change);
26✔
51
                    }
12✔
52
                }
12✔
53
            );
12✔
54
    }
55

56
    public static void ComputedObserver<TEntity, TValue, TChange>(
57
        this EntityTypeBuilder<TEntity> entityTypeBuilder,
58
        Expression<Func<TEntity, TValue>> computedExpression,
59
        Expression<Func<TEntity, bool>>? filterExpression,
60
        ChangeCalculationSelector<TValue, TChange> calculationSelector,
61
        Func<ComputedChangeEventData<TEntity, TChange>, Task> callback)
62
        where TEntity : class
63
    {
64
        var changeCalculation = calculationSelector(ChangeCalculations<TValue>.Instance);
12✔
65

66
        entityTypeBuilder.Metadata.AddObserverFactory(
12✔
67
            ObserverFactory.CreateObserverFactory(
12✔
68
                computedExpression,
12✔
69
                filterExpression,
12✔
70
                changeCalculation,
12✔
71
                callback));
12✔
72
    }
73

74
    public static void ConsistencyFilter<TEntity>(
75
        this EntityTypeBuilder<TEntity> entityTypeBuilder,
76
        Expression<Func<TEntity, DateTime, bool>> filter)
77
        where TEntity : class
78
    {
NEW
79
        entityTypeBuilder.Metadata.SetConsistencyFilter(filter);
×
80
    }
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc