• 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

0.0
/src/LLL.AutoCompute.EFCore/Metadata/Internal/ComputedNavigation.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 ComputedNavigation<TEntity, TProperty>(
9
    INavigationBase navigation,
10
    IUnboundChangesProvider<IEFCoreComputedInput, TEntity, TProperty> changesProvider
NEW
11
) : Computed(changesProvider)
×
12
    where TEntity : class
13
{
NEW
14
    public new IUnboundChangesProvider<IEFCoreComputedInput, TEntity, TProperty> ChangesProvider => changesProvider;
×
NEW
15
    public INavigationBase Navigation => navigation;
×
16

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

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

NEW
32
            var newValue = ChangesProvider.ChangeCalculation.IsIncremental
×
NEW
33
                ? ChangesProvider.ChangeCalculation.ApplyChange(
×
NEW
34
                    GetOriginalValue(navigationEntry),
×
NEW
35
                    change)
×
NEW
36
                : change;
×
37

NEW
38
            if (!Equals(navigationEntry.CurrentValue, newValue))
×
39
            {
NEW
40
                navigationEntry.CurrentValue = newValue;
×
NEW
41
                numberOfUpdates++;
×
42
            }
43
        }
NEW
44
        return numberOfUpdates;
×
45
    }
46

47
    private static TProperty GetOriginalValue(NavigationEntry navigationEntry)
48
    {
NEW
49
        if (navigationEntry.EntityEntry.State == EntityState.Added)
×
NEW
50
            return default!;
×
51

NEW
52
        return (TProperty)navigationEntry.GetOriginalValue()!;
×
53
    }
54
}
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