• 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/ComputedReaction.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 ComputedReaction(
9
    IPropertyBase property,
10
    IUnboundChangesProvider changesProvider
NEW
11
) : Computed(changesProvider)
×
12
{
NEW
13
    public IPropertyBase Property => property;
×
14
}
15
public class ComputedReaction<TEntity, TProperty, TChange>(
16
    IPropertyBase property,
17
    IUnboundChangesProvider<IEFCoreComputedInput, TEntity, TChange> changesProvider,
18
    Func<TProperty, TChange, TProperty> applyChange
NEW
19
) : ComputedReaction(property, changesProvider)
×
20
    where TEntity : class
21
{
22
    public override string ToDebugString()
23
    {
NEW
24
        return Property.ToString()!;
×
25
    }
26

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

NEW
37
            if (memberEntry is NavigationEntry navigationEntry)
×
NEW
38
                await navigationEntry.LoadAsync();
×
39

NEW
40
            var newValue = applyChange(
×
NEW
41
                (TProperty)memberEntry.CurrentValue!,
×
NEW
42
                change);
×
43

NEW
44
            if (!Equals(memberEntry.CurrentValue, newValue))
×
45
            {
NEW
46
                memberEntry.CurrentValue = newValue;
×
NEW
47
                numberOfUpdates++;
×
48
            }
49
        }
NEW
50
        return numberOfUpdates;
×
51
    }
52
}
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