Use properties directly instead of backing fields for root rewritter

This commit is contained in:
2023-11-06 12:52:21 +01:00
parent 922dcda20d
commit 8d2b231e31
@@ -286,20 +286,19 @@ namespace EntityFrameworkCore.Projectables.Services
var properties = entityType.GetProperties() var properties = entityType.GetProperties()
.Where(x => !x.IsShadowProperty()) .Where(x => !x.IsShadowProperty())
.Select(x => x.GetMemberInfo(false, false)) .Select(x => x.PropertyInfo as MemberInfo ?? x.FieldInfo!)
.Concat(entityType.GetNavigations() .Concat(entityType.GetNavigations()
.Where(x => !x.IsShadowProperty()) .Where(x => !x.IsShadowProperty())
.Select(x => x.GetMemberInfo(false, false))) .Select(x => x.PropertyInfo as MemberInfo ?? x.FieldInfo!))
.Concat(entityType.GetSkipNavigations() .Concat(entityType.GetSkipNavigations()
.Where(x => !x.IsShadowProperty()) .Where(x => !x.IsShadowProperty())
.Select(x => x.GetMemberInfo(false, false))) .Select(x => x.PropertyInfo as MemberInfo ?? x.FieldInfo!))
// Remove projectable properties from the ef properties. Since properties returned here for auto // Remove projectable properties from the ef properties.
// properties (like `public string Test {get;set;}`) are generated fields, we also need to take them into account. .Where(x => projectableProperties.All(y => x.Name != y.Name));
.Where(x => projectableProperties.All(y => x.Name != y.Name && x.Name != $"<{y.Name}>k__BackingField"));
// Replace db.Entities to db.Entities.Select(x => new Entity { Property1 = x.Property1, Rewritted = rewrittedProperty }) // Replace db.Entities to db.Entities.Select(x => new Entity { Property1 = x.Property1, Rewritted = rewrittedProperty })
var select = _select.MakeGenericMethod(entityType.ClrType, entityType.ClrType); var select = _select.MakeGenericMethod(entityType.ClrType, entityType.ClrType);
var xParam = Expression.Parameter(entityType.ClrType); var xParam = Expression.Parameter(entityType.ClrType, "x");
return Expression.Call( return Expression.Call(
null, null,
select, select,