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