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

lucaslorentz / auto-compute / 20626184500

31 Dec 2025 07:56PM UTC coverage: 80.751% (-0.7%) from 81.446%
20626184500

push

github

lucaslorentz
Allow customizing the consistency equality

0 of 20 new or added lines in 5 files covered. (0.0%)

1892 of 2343 relevant lines covered (80.75%)

867.46 hits per line

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

60.0
/src/LLL.AutoCompute.EFCore/Metadata/Internal/ComputedProperty.cs
1
using System.Linq.Expressions;
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 class ComputedProperty<TEntity, TProperty>(
9
    IProperty property,
10
    IComputedChangesProvider<TEntity, TProperty> changesProvider
11
) : ComputedMember<TEntity, TProperty>(changesProvider)
154✔
12
    where TEntity : class
13
{
14
    private readonly Func<TEntity, TProperty> _compiledExpression = ((Expression<Func<TEntity, TProperty>>)changesProvider.Expression).Compile();
154✔
15

16
    public new IComputedChangesProvider<TEntity, TProperty> ChangesProvider => changesProvider;
3,130✔
17
    public override IProperty Property => property;
3,284✔
18

19
    public override async Task<EFCoreChangeset> Update(ComputedInput input)
20
    {
21
        var dbContext = input.Get<DbContext>();
1,934✔
22
        var updateChanges = new EFCoreChangeset();
1,934✔
23
        var changes = await changesProvider.GetChangesAsync(input, null);
1,934✔
24
        foreach (var (entity, change) in changes)
10,128✔
25
        {
26
            var entityEntry = dbContext.Entry(entity);
3,130✔
27
            var propertyEntry = entityEntry.Property(Property);
3,130✔
28

29
            var newValue = ChangesProvider.ChangeCalculator.ApplyChange(
3,130✔
30
                GetOriginalValue(propertyEntry),
3,130✔
31
                change);
3,130✔
32

33
            MaybeUpdateProperty(propertyEntry, newValue, updateChanges);
3,130✔
34
        }
35
        return updateChanges;
1,934✔
36
    }
37

38
    public override async Task FixAsync(object entity, DbContext dbContext)
39
    {
40
        var entityEntry = dbContext.Entry(entity);
×
41
        var propertyEntry = entityEntry.Property(Property);
×
42

43
        var newValue = _compiledExpression((TEntity)entity);
×
44

45
        MaybeUpdateProperty(propertyEntry, newValue, null);
×
46
    }
47

48
    private static TProperty GetOriginalValue(PropertyEntry propertyEntry)
49
    {
50
        if (propertyEntry.EntityEntry.State == EntityState.Added)
3,130✔
51
            return default!;
2,960✔
52

53
        return (TProperty)propertyEntry.OriginalValue!;
170✔
54
    }
55

56
    protected override Expression CreateIsValueConsistentExpression(Expression computedValue, Expression storedValue)
57
    {
NEW
58
        var consistencyCheckEquals = (Expression<Func<TProperty, TProperty, bool>>?)Property.GetConsistencyEquality();
×
59

NEW
60
        if (consistencyCheckEquals is not null)
×
NEW
61
            return consistencyCheckEquals.UnwrapLambda([computedValue, storedValue]);
×
62

63
        return Expression.Call(
×
64
            typeof(object), nameof(object.Equals), [],
×
65
            Expression.Convert(computedValue, typeof(object)),
×
66
            Expression.Convert(storedValue, typeof(object))
×
67
        );
×
68
    }
69
}
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