• 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

90.48
/src/LLL.AutoCompute.EFCore/Metadata/Internal/ComputedProperty.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 ComputedProperty(
9
    IProperty property,
10
    LambdaExpression computedExpression)
11
    : Computed(computedExpression)
6✔
12
{
NEW
13
    public override IEntityType EntityType => (IEntityType)property.DeclaringType;
×
14
    public IProperty Property => property;
168✔
15
}
16

17
public class ComputedProperty<TEntity, TProperty, TChange>(
18
    IProperty property,
19
    IUnboundChangesProvider<IEFCoreComputedInput, TEntity, TChange> changesProvider,
20
    LambdaExpression computedExpression,
21
    Func<TProperty, TChange, TProperty> applyChange
22
) : ComputedProperty(property, computedExpression)
6✔
23
    where TEntity : class
24
{
25
    public override string ToDebugString()
26
    {
NEW
27
        return Property.ToDebugString();
×
28
    }
29

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

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

45
            var originalValue = entityEntry.State == EntityState.Added
84✔
46
                ? default!
84✔
47
                : (TProperty)propertyEntry.OriginalValue!;
84✔
48

49
            var newValue = applyChange(originalValue, change);
84✔
50

51
            var valueComparer = Property.GetValueComparer();
84✔
52
            if (!valueComparer.Equals(propertyEntry.CurrentValue, newValue))
84✔
53
            {
54
                propertyEntry.CurrentValue = newValue;
70✔
55
                numberOfUpdates++;
70✔
56
            }
57
        }
58
        return numberOfUpdates;
70✔
59
    }
60
}
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