diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs index 85b36ba0cb4..e69b5e0acf6 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs @@ -200,7 +200,7 @@ public virtual void ReplaceProjection(IReadOnlyDictionary(); - foreach (var property in GetAllPropertiesInHierarchy(entityProjectionExpression.EntityType)) + foreach (var property in entityProjectionExpression.EntityType.GetAllPropertiesInHierarchy()) { var expression = entityProjectionExpression.BindProperty(property); selectorExpressions.Add(expression); @@ -266,7 +266,7 @@ public virtual void ApplyProjection() case EntityProjectionExpression entityProjectionExpression: { var indexMap = new Dictionary(); - foreach (var property in GetAllPropertiesInHierarchy(entityProjectionExpression.EntityType)) + foreach (var property in entityProjectionExpression.EntityType.GetAllPropertiesInHierarchy()) { selectorExpressions.Add(entityProjectionExpression.BindProperty(property)); indexMap[property] = selectorExpressions.Count - 1; @@ -307,7 +307,7 @@ public virtual void ApplyProjection() if (expression is EntityProjectionExpression entityProjectionExpression) { var indexMap = new Dictionary(); - foreach (var property in GetAllPropertiesInHierarchy(entityProjectionExpression.EntityType)) + foreach (var property in entityProjectionExpression.EntityType.GetAllPropertiesInHierarchy()) { selectorExpressions.Add(entityProjectionExpression.BindProperty(property)); indexMap[property] = selectorExpressions.Count - 1; @@ -384,7 +384,7 @@ public virtual void ApplySetOperation(MethodInfo setOperationMethodInfo, InMemor && value2 is EntityProjectionExpression entityProjection2) { var map = new Dictionary(); - foreach (var property in GetAllPropertiesInHierarchy(entityProjection1.EntityType)) + foreach (var property in entityProjection1.EntityType.GetAllPropertiesInHierarchy()) { var expressionToAdd1 = entityProjection1.BindProperty(property); var expressionToAdd2 = entityProjection2.BindProperty(property); @@ -674,7 +674,7 @@ public virtual StructuralTypeShaperExpression AddNavigationToWeakEntityType( var outerIndex = selectorExpressions.Count; var innerEntityProjection = (EntityProjectionExpression)innerQueryExpression._projectionMapping[new ProjectionMember()]; var innerReadExpressionMap = new Dictionary(); - foreach (var property in GetAllPropertiesInHierarchy(innerEntityProjection.EntityType)) + foreach (var property in innerEntityProjection.EntityType.GetAllPropertiesInHierarchy()) { var propertyExpression = innerEntityProjection.BindProperty(property); propertyExpression = MakeReadValueNullable(propertyExpression); @@ -874,7 +874,7 @@ private static Expression GetGroupingKey(Expression key, List groupi (EntityProjectionExpression)((InMemoryQueryExpression)projectionBindingExpression.QueryExpression) .GetProjection(projectionBindingExpression); var readExpressions = new Dictionary(); - foreach (var property in GetAllPropertiesInHierarchy(entityProjectionExpression.EntityType)) + foreach (var property in entityProjectionExpression.EntityType.GetAllPropertiesInHierarchy()) { readExpressions[property] = (MethodCallExpression)GetGroupingKey( entityProjectionExpression.BindProperty(property), @@ -1156,10 +1156,6 @@ private void ConvertToEnumerable() private MethodCallExpression CreateReadValueExpression(Type type, int index, IPropertyBase? property) => (MethodCallExpression)_valueBufferParameter.CreateValueBufferReadValueExpression(type, index, property); - private static IEnumerable GetAllPropertiesInHierarchy(IEntityType entityType) - => entityType.GetAllBaseTypes().Concat(entityType.GetDerivedTypesInclusive()) - .SelectMany(t => t.GetDeclaredProperties()); - private static IPropertyBase? InferPropertyFromInner(Expression expression) => expression is MethodCallExpression { Method.IsGenericMethod: true } methodCallExpression && methodCallExpression.Method.GetGenericMethodDefinition() == ExpressionExtensions.ValueBufferTryReadValueMethod @@ -1169,7 +1165,7 @@ private static IEnumerable GetAllPropertiesInHierarchy(IEntityType en private static EntityProjectionExpression MakeEntityProjectionNullable(EntityProjectionExpression entityProjectionExpression) { var readExpressionMap = new Dictionary(); - foreach (var property in GetAllPropertiesInHierarchy(entityProjectionExpression.EntityType)) + foreach (var property in entityProjectionExpression.EntityType.GetAllPropertiesInHierarchy()) { readExpressionMap[property] = MakeReadValueNullable(entityProjectionExpression.BindProperty(property)); } @@ -1277,7 +1273,7 @@ private EntityProjectionExpression TraverseEntityProjection( bool makeNullable) { var readExpressionMap = new Dictionary(); - foreach (var property in GetAllPropertiesInHierarchy(entityProjectionExpression.EntityType)) + foreach (var property in entityProjectionExpression.EntityType.GetAllPropertiesInHierarchy()) { var expression = entityProjectionExpression.BindProperty(property); if (makeNullable) diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerQueryableMethodTranslatingExpressionVisitor.cs index ad644c88069..80e558a570e 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerQueryableMethodTranslatingExpressionVisitor.cs @@ -336,7 +336,7 @@ protected override ShapedQueryExpression TransformJsonQueryToTable(JsonQueryExpr var columnInfos = new List(); // We're only interested in properties which actually exist in the JSON, filter out uninteresting shadow keys - foreach (var property in GetAllPropertiesInHierarchy(jsonQueryExpression.EntityType)) + foreach (var property in jsonQueryExpression.EntityType.GetAllPropertiesInHierarchy()) { if (property.GetJsonPropertyName() is string jsonPropertyName) { @@ -351,7 +351,7 @@ protected override ShapedQueryExpression TransformJsonQueryToTable(JsonQueryExpr } } - foreach (var navigation in GetAllNavigationsInHierarchy(jsonQueryExpression.EntityType) + foreach (var navigation in jsonQueryExpression.EntityType.GetAllNavigationsInHierarchy() .Where( n => n.ForeignKey.IsOwnership && n.TargetEntityType.IsMappedToJson() @@ -405,15 +405,6 @@ protected override ShapedQueryExpression TransformJsonQueryToTable(JsonQueryExpr new ProjectionMember(), typeof(ValueBuffer)), false)); - - // TODO: Move these to IEntityType? - static IEnumerable GetAllPropertiesInHierarchy(IEntityType entityType) - => entityType.GetAllBaseTypes().Concat(entityType.GetDerivedTypesInclusive()) - .SelectMany(t => t.GetDeclaredProperties()); - - static IEnumerable GetAllNavigationsInHierarchy(IEntityType entityType) - => entityType.GetAllBaseTypes().Concat(entityType.GetDerivedTypesInclusive()) - .SelectMany(t => t.GetDeclaredNavigations()); } /// diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitor.cs index e5849c3292e..2b6a512d2a5 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitor.cs @@ -351,7 +351,7 @@ protected override ShapedQueryExpression TransformJsonQueryToTable(JsonQueryExpr // (SELECT value ->> 'a' AS a, value ->> 'b' AS b FROM json_each(c."JsonColumn", '$.Something.SomeCollection') // We're only interested in properties which actually exist in the JSON, filter out uninteresting shadow keys - foreach (var property in GetAllPropertiesInHierarchy(entityType)) + foreach (var property in entityType.GetAllPropertiesInHierarchy()) { if (property.GetJsonPropertyName() is string jsonPropertyName) { @@ -369,7 +369,7 @@ protected override ShapedQueryExpression TransformJsonQueryToTable(JsonQueryExpr } } - foreach (var navigation in GetAllNavigationsInHierarchy(jsonQueryExpression.EntityType) + foreach (var navigation in jsonQueryExpression.EntityType.GetAllNavigationsInHierarchy() .Where( n => n.ForeignKey.IsOwnership && n.TargetEntityType.IsMappedToJson() @@ -426,15 +426,6 @@ protected override ShapedQueryExpression TransformJsonQueryToTable(JsonQueryExpr new ProjectionMember(), typeof(ValueBuffer)), false)); - - // TODO: Move these to IEntityType? - static IEnumerable GetAllPropertiesInHierarchy(IEntityType entityType) - => entityType.GetAllBaseTypes().Concat(entityType.GetDerivedTypesInclusive()) - .SelectMany(t => t.GetDeclaredProperties()); - - static IEnumerable GetAllNavigationsInHierarchy(IEntityType entityType) - => entityType.GetAllBaseTypes().Concat(entityType.GetDerivedTypesInclusive()) - .SelectMany(t => t.GetDeclaredNavigations()); } ///