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

lucaslorentz / auto-compute / 11758855041

09 Nov 2024 07:22PM UTC coverage: 77.28% (+0.07%) from 77.208%
11758855041

push

github

lucaslorentz
Add initial support for computed navigations and observers

166 of 431 new or added lines in 25 files covered. (38.52%)

41 existing lines in 7 files now uncovered.

1466 of 1897 relevant lines covered (77.28%)

109.91 hits per line

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

95.83
/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 abstract class ComputedProperty(
9
    IProperty property,
10
    IUnboundChangesProvider changesProvider
11
) : Computed(changesProvider)
6✔
12
{
13
    public IProperty Property => property;
168✔
14
}
15

16
public class ComputedProperty<TEntity, TProperty>(
17
    IProperty property,
18
    IUnboundChangesProvider<IEFCoreComputedInput, TEntity, TProperty> changesProvider
19
) : ComputedProperty(property, changesProvider)
6✔
20
    where TEntity : class
21
{
22
    public new IUnboundChangesProvider<IEFCoreComputedInput, TEntity, TProperty> ChangesProvider => changesProvider;
104✔
23

24
    public override string ToDebugString()
25
    {
NEW
26
        return Property.ToDebugString();
×
27
    }
28

29
    public override async Task<int> Update(DbContext dbContext)
30
    {
31
        var numberOfUpdates = 0;
70✔
32
        var input = dbContext.GetComputedInput();
70✔
33
        var changes = await changesProvider.GetChangesAsync(input, null);
70✔
34
        foreach (var (entity, change) in changes)
308✔
35
        {
36
            var entityEntry = dbContext.Entry(entity);
84✔
37
            var propertyEntry = entityEntry.Property(Property);
84✔
38

39
            var newValue = ChangesProvider.ChangeCalculation.IsIncremental
84✔
40
                ? ChangesProvider.ChangeCalculation.ApplyChange(
84✔
41
                    GetOriginalValue(propertyEntry),
84✔
42
                    change)
84✔
43
                : change;
84✔
44

45
            var valueComparer = Property.GetValueComparer();
84✔
46
            if (!valueComparer.Equals(propertyEntry.CurrentValue, newValue))
84✔
47
            {
48
                propertyEntry.CurrentValue = newValue;
70✔
49
                numberOfUpdates++;
70✔
50
            }
51
        }
52
        return numberOfUpdates;
70✔
53
    }
54

55
    private static TProperty GetOriginalValue(PropertyEntry propertyEntry)
56
    {
57
        if (propertyEntry.EntityEntry.State == EntityState.Added)
20✔
58
            return default!;
11✔
59

60
        return (TProperty)propertyEntry.OriginalValue!;
9✔
61
    }
62
}
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