mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-08-15 18:44:57 +00:00
Use properties directly instead of backing fields for root rewritter
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user