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

lucaslorentz / auto-compute / 11750808709

08 Nov 2024 11:01PM UTC coverage: 81.803% (+0.4%) from 81.44%
11750808709

push

github

lucaslorentz
Add initial support for computed navigations and observers

151 of 309 new or added lines in 14 files covered. (48.87%)

12 existing lines in 5 files now uncovered.

1452 of 1775 relevant lines covered (81.8%)

116.37 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 System.Linq.Expressions;
2
using LLL.AutoCompute.EFCore.Internal;
3
using Microsoft.EntityFrameworkCore;
4
using Microsoft.EntityFrameworkCore.Metadata;
5

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

8
public abstract class ComputedNavigation(
9
    INavigationBase navigation,
10
    LambdaExpression computedExpression)
NEW
11
    : Computed(computedExpression)
×
12
{
NEW
13
    public override IEntityType EntityType => navigation.DeclaringEntityType;
×
NEW
14
    public INavigationBase Navigation => navigation;
×
15
}
16

17
public class ComputedNavigation<TEntity, TProperty, TChange>(
18
    INavigationBase navigation,
19
    IUnboundChangesProvider<IEFCoreComputedInput, TEntity, TChange> changesProvider,
20
    LambdaExpression computedExpression,
21
    Func<TProperty, TChange, TProperty> applyChange
NEW
22
) : ComputedNavigation(navigation, computedExpression)
×
23
    where TEntity : class
24
{
25
    public override string ToDebugString()
26
    {
NEW
27
        return Navigation.ToString()!;
×
28
    }
29

30
    public override IEnumerable<IEntityMember> GetDependencies()
31
    {
NEW
32
        return changesProvider.EntityContext.AllAccessedMembers;
×
33
    }
34

35
    public override async Task<int> Update(DbContext dbContext)
36
    {
NEW
37
        var numberOfUpdates = 0;
×
NEW
38
        var input = dbContext.GetComputedInput();
×
NEW
39
        var changes = await changesProvider.GetChangesAsync(input, null);
×
NEW
40
        foreach (var (entity, change) in changes)
×
41
        {
NEW
42
            var entityEntry = dbContext.Entry(entity);
×
NEW
43
            var navigationEntry = entityEntry.Navigation(Navigation);
×
44

NEW
45
            if (!navigationEntry.IsLoaded && entityEntry.State != EntityState.Detached)
×
NEW
46
                await navigationEntry.LoadAsync();
×
47

NEW
48
            var originalValue = entityEntry.State == EntityState.Added
×
NEW
49
                ? default!
×
NEW
50
                : (TProperty)navigationEntry.GetOriginalValue()!;
×
51

NEW
52
            var newValue = applyChange(originalValue, change);
×
53

NEW
54
            if (!Equals(originalValue, newValue))
×
55
            {
NEW
56
                navigationEntry.CurrentValue = newValue;
×
NEW
57
                numberOfUpdates++;
×
58
            }
59
        }
NEW
60
        return numberOfUpdates;
×
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