mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2025-12-06 05:56:10 +00:00
Only includes relations eagerly included
This commit is contained in:
@@ -18,6 +18,7 @@ namespace EntityFrameworkCore.Projectables.Services
|
||||
readonly Dictionary<MemberInfo, LambdaExpression?> _projectableMemberCache = new();
|
||||
private bool _disableRootRewrite;
|
||||
private List<string> _includedProjections = new();
|
||||
private List<string> _includedRelations = new();
|
||||
private IEntityType? _entityType;
|
||||
|
||||
private readonly MethodInfo _select;
|
||||
@@ -63,6 +64,7 @@ namespace EntityFrameworkCore.Projectables.Services
|
||||
{
|
||||
_disableRootRewrite = false;
|
||||
_includedProjections.Clear();
|
||||
_includedRelations.Clear();
|
||||
var ret = Visit(node);
|
||||
|
||||
if (_disableRootRewrite)
|
||||
@@ -161,6 +163,10 @@ namespace EntityFrameworkCore.Projectables.Services
|
||||
_includedProjections.Add(include);
|
||||
return ret;
|
||||
}
|
||||
else if (include != null)
|
||||
{
|
||||
_includedRelations.Add(include);
|
||||
}
|
||||
}
|
||||
|
||||
// Replace MethodGroup arguments with their reflected expressions.
|
||||
@@ -287,12 +293,15 @@ namespace EntityFrameworkCore.Projectables.Services
|
||||
var properties = entityType.GetProperties()
|
||||
.Where(x => !x.IsShadowProperty())
|
||||
.Select(x => x.PropertyInfo as MemberInfo ?? x.FieldInfo!)
|
||||
.Concat(entityType.GetNavigations()
|
||||
.Where(x => !x.IsShadowProperty())
|
||||
.Select(x => x.PropertyInfo as MemberInfo ?? x.FieldInfo!))
|
||||
.Concat(entityType.GetSkipNavigations()
|
||||
.Where(x => !x.IsShadowProperty())
|
||||
.Select(x => x.PropertyInfo as MemberInfo ?? x.FieldInfo!))
|
||||
.Concat(
|
||||
entityType.GetNavigations()
|
||||
.Where(x => !x.IsShadowProperty())
|
||||
.Select(x => x.PropertyInfo as MemberInfo ?? x.FieldInfo!)
|
||||
.Concat(entityType.GetSkipNavigations()
|
||||
.Where(x => !x.IsShadowProperty())
|
||||
.Select(x => x.PropertyInfo as MemberInfo ?? x.FieldInfo!))
|
||||
.Where(x => _includedRelations.Contains(x.Name))
|
||||
)
|
||||
// Remove projectable properties from the ef properties.
|
||||
.Where(x => projectableProperties.All(y => x.Name != y.Name));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user