• 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

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 abstract class ComputedNavigation(
9
    INavigationBase navigation,
10
    IUnboundChangesProvider changesProvider
NEW
11
) : Computed(changesProvider)
×
12
{
NEW
13
    public INavigationBase Navigation => navigation;
×
14
}
15

16
public class ComputedNavigation<TEntity, TProperty>(
17
    INavigationBase navigation,
18
    IUnboundChangesProvider<IEFCoreComputedInput, TEntity, TProperty> changesProvider
NEW
19
) : ComputedNavigation(navigation, changesProvider)
×
20
    where TEntity : class
21
{
NEW
22
    public new IUnboundChangesProvider<IEFCoreComputedInput, TEntity, TProperty> ChangesProvider => changesProvider;
×
23

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

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

NEW
39
            var newValue = ChangesProvider.ChangeCalculation.IsIncremental
×
NEW
40
                ? ChangesProvider.ChangeCalculation.ApplyChange(
×
NEW
41
                    GetOriginalValue(navigationEntry),
×
NEW
42
                    change)
×
NEW
43
                : change;
×
44

NEW
45
            if (!Equals(navigationEntry.CurrentValue, newValue))
×
46
            {
NEW
47
                navigationEntry.CurrentValue = newValue;
×
NEW
48
                numberOfUpdates++;
×
49
            }
50
        }
NEW
51
        return numberOfUpdates;
×
52
    }
53

54
    private static TProperty GetOriginalValue(NavigationEntry navigationEntry)
55
    {
NEW
56
        if (navigationEntry.EntityEntry.State == EntityState.Added)
×
NEW
57
            return default!;
×
58

NEW
59
        return (TProperty)navigationEntry.GetOriginalValue()!;
×
60
    }
61
}
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