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

lucaslorentz / auto-compute / 18778187096

24 Oct 2025 11:14AM UTC coverage: 83.295% (-0.2%) from 83.516%
18778187096

push

github

lucaslorentz
Move IncrementalContext param into Input param

56 of 58 new or added lines in 22 files covered. (96.55%)

8 existing lines in 5 files now uncovered.

1790 of 2149 relevant lines covered (83.29%)

880.64 hits per line

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

88.89
/src/LLL.AutoCompute.EFCore/Internal/EFCoreObservedProperty.cs
1
using System.Linq.Expressions;
2
using System.Reflection;
3
using Microsoft.EntityFrameworkCore;
4
using Microsoft.EntityFrameworkCore.ChangeTracking;
5
using Microsoft.EntityFrameworkCore.Metadata;
6

7
namespace LLL.AutoCompute.EFCore.Internal;
8

9
public class EFCoreObservedProperty(
140✔
10
    IProperty property)
140✔
11
    : EFCoreObservedMember, IObservedProperty<EFCoreComputedInput>
12
{
13
    public override IProperty Property => property;
14,054✔
14
    public override string Name => Property.Name;
×
15
    public virtual Type EntityType => Property.DeclaringType.ClrType;
×
16

17
    public override string ToDebugString()
18
    {
19
        return $"{Property.DeclaringType.ShortName()}.{Property.Name}";
×
20
    }
21

22
    public override Expression CreateOriginalValueExpression(
23
        IObservedMemberAccess memberAccess,
24
        Expression inputExpression)
25
    {
26
        return Expression.Convert(
270✔
27
            Expression.Call(
270✔
28
                Expression.Constant(this),
270✔
29
                GetType().GetMethod(nameof(GetOriginalValue), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy)!,
270✔
30
                inputExpression,
270✔
31
                memberAccess.FromExpression
270✔
32
            ),
270✔
33
            Property.ClrType
270✔
34
        );
270✔
35
    }
36

37
    public override Expression CreateCurrentValueExpression(
38
        IObservedMemberAccess memberAccess,
39
        Expression inputExpression)
40
    {
41
        return Expression.Convert(
270✔
42
            Expression.Call(
270✔
43
                Expression.Constant(this),
270✔
44
                GetType().GetMethod(nameof(GetCurrentValue), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy)!,
270✔
45
                inputExpression,
270✔
46
                memberAccess.FromExpression
270✔
47
            ),
270✔
48
            Property.ClrType
270✔
49
        );
270✔
50
    }
51

52
    protected virtual object? GetOriginalValue(EFCoreComputedInput input, object ent)
53
    {
54
        var dbContext = input.DbContext;
122✔
55

56
        var entityEntry = dbContext.Entry(ent!);
122✔
57

58
        if (entityEntry.State == EntityState.Added)
122✔
UNCOV
59
            throw new Exception($"Cannot access property '{Property.DeclaringType.ShortName()}.{Property.Name}' original value for an added entity");
×
60

61
        return entityEntry.Property(Property).OriginalValue;
122✔
62
    }
63

64
    protected virtual object? GetCurrentValue(EFCoreComputedInput input, object ent)
65
    {
66
        var dbContext = input.DbContext;
3,418✔
67

68
        var entityEntry = dbContext.Entry(ent!);
3,418✔
69

70
        if (entityEntry.State == EntityState.Deleted)
3,418✔
UNCOV
71
            throw new Exception($"Cannot access property '{Property.DeclaringType.ShortName()}.{Property.Name}' current value for a deleted entity");
×
72

73
        return entityEntry.Property(Property).CurrentValue;
3,418✔
74
    }
75

76
    public override async Task CollectChangesAsync(DbContext dbContext, EFCoreChangeset changes)
77
    {
78
        foreach (var entityEntry in dbContext.EntityEntriesOfType(Property.DeclaringType))
9,896✔
79
        {
80
            await CollectChangesAsync(entityEntry, changes);
3,078✔
81
        }
82
    }
83

84
    public override async Task CollectChangesAsync(EntityEntry entityEntry, EFCoreChangeset changes)
85
    {
86
        if (entityEntry.State == EntityState.Added
3,086✔
87
            || entityEntry.State == EntityState.Deleted
3,086✔
88
            || entityEntry.State == EntityState.Modified)
3,086✔
89
        {
90
            var propertyEntry = entityEntry.Property(Property);
2,720✔
91
            if (entityEntry.State == EntityState.Added
2,720✔
92
                || entityEntry.State == EntityState.Deleted
2,720✔
93
                || propertyEntry.IsModified)
2,720✔
94
            {
95
                changes.AddPropertyChange(Property, entityEntry.Entity);
2,584✔
96
            }
97
        }
98
    }
99

100
    public async Task<ObservedPropertyChanges> GetChangesAsync(EFCoreComputedInput input)
101
    {
102
        return input.ChangesToProcess.GetOrCreatePropertyChanges(Property);
2,628✔
103
    }
104
}
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