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

lucaslorentz / auto-compute / 11911066930

19 Nov 2024 10:25AM UTC coverage: 81.029% (+4.2%) from 76.855%
11911066930

push

github

lucaslorentz
Improve EFCore computeds

27 of 85 new or added lines in 12 files covered. (31.76%)

3 existing lines in 1 file now uncovered.

1465 of 1808 relevant lines covered (81.03%)

115.3 hits per line

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

22.58
/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
        where TEntity : class
14
    {
15
        return ComputedProperty(
8✔
16
            entityTypeBuilder,
8✔
17
            propertyExpression,
8✔
18
            computedExpression,
8✔
19
            static c => c.CurrentValue());
16✔
20
    }
21

22
    public static PropertyBuilder<TProperty> ComputedProperty<TEntity, TProperty>(
23
        this EntityTypeBuilder<TEntity> entityTypeBuilder,
24
        Expression<Func<TEntity, TProperty>> propertyExpression,
25
        Expression<Func<TEntity, TProperty>> computedExpression,
26
        ChangeCalculationSelector<TProperty, TProperty> calculationSelector)
27
        where TEntity : class
28
    {
29
        return entityTypeBuilder.Property(propertyExpression)
12✔
30
            .AutoCompute(computedExpression, calculationSelector);
12✔
31
    }
32

33
    public static NavigationBuilder<TEntity, TReference> ComputedNavigation<TEntity, TReference>(
34
        this EntityTypeBuilder<TEntity> entityTypeBuilder,
35
        Expression<Func<TEntity, TReference>> navigationExpression,
36
        Expression<Func<TEntity, TReference>> computedExpression)
37
        where TEntity : class
38
        where TReference : class
39
    {
40
        return entityTypeBuilder.ComputedNavigation(
×
41
            navigationExpression,
×
42
            computedExpression,
×
43
            static c => c.CurrentValue());
×
44
    }
45

46
    public static NavigationBuilder<TEntity, TProperty> ComputedNavigation<TEntity, TProperty>(
47
        this EntityTypeBuilder<TEntity> entityTypeBuilder,
48
        Expression<Func<TEntity, TProperty>> navigationExpression,
49
        Expression<Func<TEntity, TProperty>> computedExpression,
50
        ChangeCalculationSelector<TProperty, TProperty> calculationSelector)
51
        where TEntity : class
52
        where TProperty : class
53
    {
54
        return entityTypeBuilder.Navigation(navigationExpression!)
×
55
            .AutoCompute(computedExpression, calculationSelector);
×
56
    }
57

58
    public static void ComputedObserver<TEntity, TValue, TChange>(
59
        this EntityTypeBuilder<TEntity> entityTypeBuilder,
60
        Expression<Func<TEntity, TValue>> computedExpression,
61
        ChangeCalculationSelector<TValue, TChange> calculationSelector,
62
        Func<TEntity, TChange?, Task> callback)
63
        where TEntity : class
64
    {
65
        entityTypeBuilder
×
66
            .ComputedObserver(
×
67
                computedExpression,
×
68
                calculationSelector,
×
69
                async (ComputedChangeEventData<TEntity, TChange> eventData) =>
×
70
                {
×
71
                    foreach (var (entity, change) in eventData.Changes)
×
72
                    {
×
73
                        await callback(entity, change);
×
74
                    }
×
75
                }
×
76
            );
×
77
    }
78

79
    public static void ComputedObserver<TEntity, TValue, TChange>(
80
        this EntityTypeBuilder<TEntity> entityTypeBuilder,
81
        Expression<Func<TEntity, TValue>> computedExpression,
82
        ChangeCalculationSelector<TValue, TChange> calculationSelector,
83
        Func<ComputedChangeEventData<TEntity, TChange>, Task> callback)
84
        where TEntity : class
85
    {
86
        var changeCalculation = calculationSelector(ChangeCalculations<TValue>.Instance);
×
87

NEW
88
        entityTypeBuilder.Metadata.AddObserverFactory(
×
NEW
89
            ObserverFactory.CreateObserverFactory(
×
90
                computedExpression,
×
91
                changeCalculation,
×
92
                callback));
×
93
    }
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc