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

lucaslorentz / auto-compute / 11755625072

09 Nov 2024 10:48AM UTC coverage: 79.945% (-0.09%) from 80.033%
11755625072

push

github

lucaslorentz
Add initial support for computed navigations and observers

159 of 359 new or added lines in 22 files covered. (44.29%)

41 existing lines in 7 files now uncovered.

1459 of 1825 relevant lines covered (79.95%)

113.62 hits per line

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

95.65
/src/LLL.AutoCompute.EFCore/Metadata/Internal/ComputedProperty.cs
1
using LLL.AutoCompute.EFCore.Internal;
2
using Microsoft.EntityFrameworkCore;
3
using Microsoft.EntityFrameworkCore.ChangeTracking;
4
using Microsoft.EntityFrameworkCore.Metadata;
5

6
namespace LLL.AutoCompute.EFCore.Metadata.Internal;
7

8
public class ComputedProperty<TEntity, TProperty>(
9
    IProperty property,
10
    IUnboundChangesProvider<IEFCoreComputedInput, TEntity, TProperty> changesProvider
11
) : Computed(changesProvider)
6✔
12
    where TEntity : class
13
{
14
    public new IUnboundChangesProvider<IEFCoreComputedInput, TEntity, TProperty> ChangesProvider => changesProvider;
104✔
15
    public IProperty Property => property;
168✔
16

17
    public override string ToDebugString()
18
    {
NEW
19
        return Property.ToDebugString();
×
20
    }
21

22
    public override async Task<int> Update(DbContext dbContext)
23
    {
24
        var numberOfUpdates = 0;
70✔
25
        var input = dbContext.GetComputedInput();
70✔
26
        var changes = await changesProvider.GetChangesAsync(input, null);
70✔
27
        foreach (var (entity, change) in changes)
308✔
28
        {
29
            var entityEntry = dbContext.Entry(entity);
84✔
30
            var propertyEntry = entityEntry.Property(Property);
84✔
31

32
            var newValue = ChangesProvider.ChangeCalculation.IsIncremental
84✔
33
                ? ChangesProvider.ChangeCalculation.ApplyChange(
84✔
34
                    GetOriginalValue(propertyEntry),
84✔
35
                    change)
84✔
36
                : change;
84✔
37

38
            var valueComparer = Property.GetValueComparer();
84✔
39
            if (!valueComparer.Equals(propertyEntry.CurrentValue, newValue))
84✔
40
            {
41
                propertyEntry.CurrentValue = newValue;
70✔
42
                numberOfUpdates++;
70✔
43
            }
44
        }
45
        return numberOfUpdates;
70✔
46
    }
47

48
    private static TProperty GetOriginalValue(PropertyEntry propertyEntry)
49
    {
50
        if (propertyEntry.EntityEntry.State == EntityState.Added)
20✔
51
            return default!;
11✔
52

53
        return (TProperty)propertyEntry.OriginalValue!;
9✔
54
    }
55
}
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