diff --git a/.editorconfig b/.editorconfig index 6f1a8c3f14b..446dc4e610c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -136,7 +136,7 @@ csharp_new_line_between_query_expression_clauses = true # Identation options csharp_indent_block_contents = true csharp_indent_braces = false -csharp_indent_case_contents_when_block = true +csharp_indent_case_contents_when_block = false csharp_indent_switch_labels = true csharp_indent_case_contents = true csharp_indent_labels = no_change @@ -253,4 +253,4 @@ dotnet_naming_symbols.everything_else.applicable_accessibilities = * dotnet_naming_rule.everything_else_naming.symbols = everything_else dotnet_naming_rule.everything_else_naming.style = camel_case_style -dotnet_naming_rule.everything_else_naming.severity = suggestion \ No newline at end of file +dotnet_naming_rule.everything_else_naming.severity = suggestion diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs index 6d60a0d8eaa..c03fb28fe5d 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs @@ -303,19 +303,19 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp nullable: true); case ObjectArrayProjectionExpression objectArrayProjectionExpression: - { - var innerShaperExpression = new EntityShaperExpression( - navigation.GetTargetType(), - Expression.Convert( - Expression.Convert(objectArrayProjectionExpression.InnerProjection, typeof(object)), typeof(ValueBuffer)), - nullable: true); - - return new CollectionShaperExpression( - objectArrayProjectionExpression, - innerShaperExpression, - navigation, - innerShaperExpression.EntityType.ClrType); - } + { + var innerShaperExpression = new EntityShaperExpression( + navigation.GetTargetType(), + Expression.Convert( + Expression.Convert(objectArrayProjectionExpression.InnerProjection, typeof(object)), typeof(ValueBuffer)), + nullable: true); + + return new CollectionShaperExpression( + objectArrayProjectionExpression, + innerShaperExpression, + navigation, + innerShaperExpression.EntityType.ClrType); + } default: throw new InvalidOperationException(); diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs index a114b52bd7e..d010f58a36b 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs @@ -1056,39 +1056,39 @@ public override Expression Visit(Expression expression) switch (inExpression.Values) { case SqlConstantExpression sqlConstant: + { + typeMapping = sqlConstant.TypeMapping; + var values = (IEnumerable)sqlConstant.Value; + foreach (var value in values) { - typeMapping = sqlConstant.TypeMapping; - var values = (IEnumerable)sqlConstant.Value; - foreach (var value in values) + if (value == null) { - if (value == null) - { - hasNullValue = true; - continue; - } - - inValues.Add(value); + hasNullValue = true; + continue; } + + inValues.Add(value); } - break; + } + break; case SqlParameterExpression sqlParameter: + { + typeMapping = sqlParameter.TypeMapping; + var values = (IEnumerable)_parametersValues[sqlParameter.Name]; + foreach (var value in values) { - typeMapping = sqlParameter.TypeMapping; - var values = (IEnumerable)_parametersValues[sqlParameter.Name]; - foreach (var value in values) + if (value == null) { - if (value == null) - { - hasNullValue = true; - continue; - } - - inValues.Add(value); + hasNullValue = true; + continue; } + + inValues.Add(value); } - break; - } + } + break; + } var updatedInExpression = inValues.Count > 0 ? _sqlExpressionFactory.In( diff --git a/src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs b/src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs index 693c468687c..f59c23c1e1f 100644 --- a/src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs +++ b/src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs @@ -148,22 +148,22 @@ private SqlExpression ApplyTypeMappingOnSqlBinary( case ExpressionType.LessThan: case ExpressionType.LessThanOrEqual: case ExpressionType.NotEqual: - { - inferredTypeMapping = ExpressionExtensions.InferTypeMapping(left, right) - ?? _typeMappingSource.FindMapping(left.Type); - resultType = typeof(bool); - resultTypeMapping = _boolTypeMapping; - } - break; + { + inferredTypeMapping = ExpressionExtensions.InferTypeMapping(left, right) + ?? _typeMappingSource.FindMapping(left.Type); + resultType = typeof(bool); + resultTypeMapping = _boolTypeMapping; + } + break; case ExpressionType.AndAlso: case ExpressionType.OrElse: - { - inferredTypeMapping = _boolTypeMapping; - resultType = typeof(bool); - resultTypeMapping = _boolTypeMapping; - } - break; + { + inferredTypeMapping = _boolTypeMapping; + resultType = typeof(bool); + resultTypeMapping = _boolTypeMapping; + } + break; case ExpressionType.Add: case ExpressionType.Subtract: @@ -175,12 +175,12 @@ private SqlExpression ApplyTypeMappingOnSqlBinary( case ExpressionType.Coalesce: case ExpressionType.And: case ExpressionType.Or: - { - inferredTypeMapping = typeMapping ?? ExpressionExtensions.InferTypeMapping(left, right); - resultType = left.Type; - resultTypeMapping = inferredTypeMapping; - } - break; + { + inferredTypeMapping = typeMapping ?? ExpressionExtensions.InferTypeMapping(left, right); + resultType = left.Type; + resultTypeMapping = inferredTypeMapping; + } + break; default: throw new InvalidOperationException("Incorrect operatorType for SqlBinaryExpression"); diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs index 19e9c92bec3..17a935acca9 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs @@ -270,13 +270,13 @@ protected override Expression VisitExtension(Expression extensionExpression) .GetMappedProjection(projectionBindingExpression.ProjectionMember); case NullConditionalExpression nullConditionalExpression: - { - var translation = Visit(nullConditionalExpression.AccessOperation); + { + var translation = Visit(nullConditionalExpression.AccessOperation); - return translation.Type == nullConditionalExpression.Type - ? translation - : Expression.Convert(translation, nullConditionalExpression.Type); - } + return translation.Type == nullConditionalExpression.Type + ? translation + : Expression.Convert(translation, nullConditionalExpression.Type); + } default: throw new InvalidOperationException(); diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs index ba40c75430c..eb3f795c16a 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs @@ -90,32 +90,32 @@ public override Expression Visit(Expression expression) throw new NotImplementedException(); case MethodCallExpression methodCallExpression: + { + if (methodCallExpression.Method.IsGenericMethod + && methodCallExpression.Method.DeclaringType == typeof(Enumerable) + && methodCallExpression.Method.Name == nameof(Enumerable.ToList)) { - if (methodCallExpression.Method.IsGenericMethod - && methodCallExpression.Method.DeclaringType == typeof(Enumerable) - && methodCallExpression.Method.Name == nameof(Enumerable.ToList)) - { - //var elementType = methodCallExpression.Method.GetGenericArguments()[0]; - - //var result = _queryableMethodTranslatingExpressionVisitor.TranslateSubquery(methodCallExpression.Arguments[0]); - - //return _selectExpression.AddCollectionProjection(result, null, elementType); - throw new NotImplementedException(); - } - - var subquery = _queryableMethodTranslatingExpressionVisitor.TranslateSubquery(methodCallExpression); - - if (subquery != null) - { - //if (subquery.ResultType == ResultType.Enumerable) - //{ - // return _selectExpression.AddCollectionProjection(subquery, null, subquery.ShaperExpression.Type); - //} - throw new NotImplementedException(); - } - - break; + //var elementType = methodCallExpression.Method.GetGenericArguments()[0]; + + //var result = _queryableMethodTranslatingExpressionVisitor.TranslateSubquery(methodCallExpression.Arguments[0]); + + //return _selectExpression.AddCollectionProjection(result, null, elementType); + throw new NotImplementedException(); } + + var subquery = _queryableMethodTranslatingExpressionVisitor.TranslateSubquery(methodCallExpression); + + if (subquery != null) + { + //if (subquery.ResultType == ResultType.Enumerable) + //{ + // return _selectExpression.AddCollectionProjection(subquery, null, subquery.ShaperExpression.Type); + //} + throw new NotImplementedException(); + } + + break; + } } diff --git a/src/EFCore.Relational/Query/Internal/InExpressionValuesExpandingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/InExpressionValuesExpandingExpressionVisitor.cs index 1d1d5258c0a..74f1c1a8925 100644 --- a/src/EFCore.Relational/Query/Internal/InExpressionValuesExpandingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/InExpressionValuesExpandingExpressionVisitor.cs @@ -35,38 +35,38 @@ public override Expression Visit(Expression expression) switch (inExpression.Values) { case SqlConstantExpression sqlConstant: + { + typeMapping = sqlConstant.TypeMapping; + var values = (IEnumerable)sqlConstant.Value; + foreach (var value in values) { - typeMapping = sqlConstant.TypeMapping; - var values = (IEnumerable)sqlConstant.Value; - foreach (var value in values) + if (value == null) { - if (value == null) - { - hasNullValue = true; - continue; - } - - inValues.Add(value); + hasNullValue = true; + continue; } + + inValues.Add(value); } - break; + } + break; case SqlParameterExpression sqlParameter: + { + typeMapping = sqlParameter.TypeMapping; + var values = (IEnumerable)_parametersValues[sqlParameter.Name]; + foreach (var value in values) { - typeMapping = sqlParameter.TypeMapping; - var values = (IEnumerable)_parametersValues[sqlParameter.Name]; - foreach (var value in values) + if (value == null) { - if (value == null) - { - hasNullValue = true; - continue; - } - - inValues.Add(value); + hasNullValue = true; + continue; } + + inValues.Add(value); } - break; + } + break; } var updatedInExpression = inValues.Count > 0 diff --git a/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs index 6313c163ab5..70118e335f8 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs @@ -98,30 +98,30 @@ public override Expression Visit(Expression expression) materializeCollectionNavigationExpression.Navigation, null); case MethodCallExpression methodCallExpression: + { + if (methodCallExpression.Method.IsGenericMethod + && methodCallExpression.Method.DeclaringType == typeof(Enumerable) + && methodCallExpression.Method.Name == nameof(Enumerable.ToList)) { - if (methodCallExpression.Method.IsGenericMethod - && methodCallExpression.Method.DeclaringType == typeof(Enumerable) - && methodCallExpression.Method.Name == nameof(Enumerable.ToList)) - { - var elementType = methodCallExpression.Method.GetGenericArguments()[0]; + var elementType = methodCallExpression.Method.GetGenericArguments()[0]; - var result = _queryableMethodTranslatingExpressionVisitor.TranslateSubquery(methodCallExpression.Arguments[0]); + var result = _queryableMethodTranslatingExpressionVisitor.TranslateSubquery(methodCallExpression.Arguments[0]); - return _selectExpression.AddCollectionProjection(result, null, elementType); - } + return _selectExpression.AddCollectionProjection(result, null, elementType); + } - var subquery = _queryableMethodTranslatingExpressionVisitor.TranslateSubquery(methodCallExpression); + var subquery = _queryableMethodTranslatingExpressionVisitor.TranslateSubquery(methodCallExpression); - if (subquery != null) + if (subquery != null) + { + if (subquery.ResultCardinality == ResultCardinality.Enumerable) { - if (subquery.ResultCardinality == ResultCardinality.Enumerable) - { - return _selectExpression.AddCollectionProjection(subquery, null, subquery.ShaperExpression.Type); - } + return _selectExpression.AddCollectionProjection(subquery, null, subquery.ShaperExpression.Type); } - - break; } + + break; + } } var translation = _sqlTranslator.Translate(expression); diff --git a/src/EFCore.Relational/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs index b14a32cc8c6..893ecdef8d2 100644 --- a/src/EFCore.Relational/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs @@ -88,93 +88,93 @@ protected override Expression VisitExtension(Expression extensionExpression) switch (extensionExpression) { case EntityShaperExpression entityShaperExpression: + { + var key = GenerateKey((ProjectionBindingExpression)entityShaperExpression.ValueBufferExpression); + if (!_mapping.TryGetValue(key, out var variable)) { - var key = GenerateKey((ProjectionBindingExpression)entityShaperExpression.ValueBufferExpression); - if (!_mapping.TryGetValue(key, out var variable)) - { - variable = Expression.Parameter(entityShaperExpression.EntityType.ClrType); - _variables.Add(variable); - _expressions.Add(Expression.Assign(variable, entityShaperExpression)); - _mapping[key] = variable; - } - - return variable; + variable = Expression.Parameter(entityShaperExpression.EntityType.ClrType); + _variables.Add(variable); + _expressions.Add(Expression.Assign(variable, entityShaperExpression)); + _mapping[key] = variable; } + return variable; + } + case ProjectionBindingExpression projectionBindingExpression: + { + var key = GenerateKey(projectionBindingExpression); + if (!_mapping.TryGetValue(key, out var variable)) { - var key = GenerateKey(projectionBindingExpression); - if (!_mapping.TryGetValue(key, out var variable)) - { - variable = Expression.Parameter(projectionBindingExpression.Type); - _variables.Add(variable); - _expressions.Add(Expression.Assign(variable, projectionBindingExpression)); - _mapping[key] = variable; - } - - return variable; + variable = Expression.Parameter(projectionBindingExpression.Type); + _variables.Add(variable); + _expressions.Add(Expression.Assign(variable, projectionBindingExpression)); + _mapping[key] = variable; } - case IncludeExpression includeExpression: - { - var entity = Visit(includeExpression.EntityExpression); - if (includeExpression.NavigationExpression is RelationalCollectionShaperExpression - relationalCollectionShaperExpression) - { - var innerShaper = new ShaperExpressionProcessingExpressionVisitor( - _selectExpression, _dataReaderParameter, _resultCoordinatorParameter, null) - .Inject(relationalCollectionShaperExpression.InnerShaper); - - _collectionPopulatingExpressions.Add(new CollectionPopulatingExpression( - relationalCollectionShaperExpression.Update( - relationalCollectionShaperExpression.ParentIdentifier, - relationalCollectionShaperExpression.OuterIdentifier, - relationalCollectionShaperExpression.SelfIdentifier, - innerShaper), - includeExpression.Navigation.ClrType, - true)); - - _expressions.Add(new CollectionInitializingExpression( - relationalCollectionShaperExpression.CollectionId, - entity, - relationalCollectionShaperExpression.ParentIdentifier, - relationalCollectionShaperExpression.OuterIdentifier, - includeExpression.Navigation, - includeExpression.Navigation.ClrType)); - } - else - { - _expressions.Add(includeExpression.Update( - entity, - Visit(includeExpression.NavigationExpression))); - } - - return entity; - } + return variable; + } - case RelationalCollectionShaperExpression relationalCollectionShaperExpression2: + case IncludeExpression includeExpression: + { + var entity = Visit(includeExpression.EntityExpression); + if (includeExpression.NavigationExpression is RelationalCollectionShaperExpression + relationalCollectionShaperExpression) { var innerShaper = new ShaperExpressionProcessingExpressionVisitor( _selectExpression, _dataReaderParameter, _resultCoordinatorParameter, null) - .Inject(relationalCollectionShaperExpression2.InnerShaper); + .Inject(relationalCollectionShaperExpression.InnerShaper); _collectionPopulatingExpressions.Add(new CollectionPopulatingExpression( - relationalCollectionShaperExpression2.Update( - relationalCollectionShaperExpression2.ParentIdentifier, - relationalCollectionShaperExpression2.OuterIdentifier, - relationalCollectionShaperExpression2.SelfIdentifier, + relationalCollectionShaperExpression.Update( + relationalCollectionShaperExpression.ParentIdentifier, + relationalCollectionShaperExpression.OuterIdentifier, + relationalCollectionShaperExpression.SelfIdentifier, innerShaper), - relationalCollectionShaperExpression2.Type, - false)); - - return new CollectionInitializingExpression( - relationalCollectionShaperExpression2.CollectionId, - null, - relationalCollectionShaperExpression2.ParentIdentifier, - relationalCollectionShaperExpression2.OuterIdentifier, - relationalCollectionShaperExpression2.Navigation, - relationalCollectionShaperExpression2.Type); + includeExpression.Navigation.ClrType, + true)); + + _expressions.Add(new CollectionInitializingExpression( + relationalCollectionShaperExpression.CollectionId, + entity, + relationalCollectionShaperExpression.ParentIdentifier, + relationalCollectionShaperExpression.OuterIdentifier, + includeExpression.Navigation, + includeExpression.Navigation.ClrType)); } + else + { + _expressions.Add(includeExpression.Update( + entity, + Visit(includeExpression.NavigationExpression))); + } + + return entity; + } + + case RelationalCollectionShaperExpression relationalCollectionShaperExpression2: + { + var innerShaper = new ShaperExpressionProcessingExpressionVisitor( + _selectExpression, _dataReaderParameter, _resultCoordinatorParameter, null) + .Inject(relationalCollectionShaperExpression2.InnerShaper); + + _collectionPopulatingExpressions.Add(new CollectionPopulatingExpression( + relationalCollectionShaperExpression2.Update( + relationalCollectionShaperExpression2.ParentIdentifier, + relationalCollectionShaperExpression2.OuterIdentifier, + relationalCollectionShaperExpression2.SelfIdentifier, + innerShaper), + relationalCollectionShaperExpression2.Type, + false)); + + return new CollectionInitializingExpression( + relationalCollectionShaperExpression2.CollectionId, + null, + relationalCollectionShaperExpression2.ParentIdentifier, + relationalCollectionShaperExpression2.OuterIdentifier, + relationalCollectionShaperExpression2.Navigation, + relationalCollectionShaperExpression2.Type); + } } return base.VisitExtension(extensionExpression); diff --git a/src/EFCore.Relational/Query/QuerySqlGenerator.cs b/src/EFCore.Relational/Query/QuerySqlGenerator.cs index 9362748db4b..2e662f9bf57 100644 --- a/src/EFCore.Relational/Query/QuerySqlGenerator.cs +++ b/src/EFCore.Relational/Query/QuerySqlGenerator.cs @@ -512,57 +512,52 @@ protected override Expression VisitSqlUnary(SqlUnaryExpression sqlUnaryExpressio switch (sqlUnaryExpression.OperatorType) { case ExpressionType.Convert: + { + _relationalCommandBuilder.Append("CAST("); + var requiresBrackets = RequiresBrackets(sqlUnaryExpression.Operand); + if (requiresBrackets) { - _relationalCommandBuilder.Append("CAST("); - var requiresBrackets = RequiresBrackets(sqlUnaryExpression.Operand); - if (requiresBrackets) - { - _relationalCommandBuilder.Append("("); - } - Visit(sqlUnaryExpression.Operand); - if (requiresBrackets) - { - _relationalCommandBuilder.Append(")"); - } - _relationalCommandBuilder.Append(" AS "); - _relationalCommandBuilder.Append(sqlUnaryExpression.TypeMapping.StoreType); - _relationalCommandBuilder.Append(")"); + _relationalCommandBuilder.Append("("); } - - break; - - case ExpressionType.Not: + Visit(sqlUnaryExpression.Operand); + if (requiresBrackets) { - _relationalCommandBuilder.Append("NOT ("); - Visit(sqlUnaryExpression.Operand); _relationalCommandBuilder.Append(")"); } + _relationalCommandBuilder.Append(" AS "); + _relationalCommandBuilder.Append(sqlUnaryExpression.TypeMapping.StoreType); + _relationalCommandBuilder.Append(")"); + } + break; - break; + case ExpressionType.Not: + { + _relationalCommandBuilder.Append("NOT ("); + Visit(sqlUnaryExpression.Operand); + _relationalCommandBuilder.Append(")"); + } + break; case ExpressionType.Equal: - { - Visit(sqlUnaryExpression.Operand); - _relationalCommandBuilder.Append(" IS NULL"); - } - - break; + { + Visit(sqlUnaryExpression.Operand); + _relationalCommandBuilder.Append(" IS NULL"); + } + break; case ExpressionType.NotEqual: - { - Visit(sqlUnaryExpression.Operand); - _relationalCommandBuilder.Append(" IS NOT NULL"); - } - - break; + { + Visit(sqlUnaryExpression.Operand); + _relationalCommandBuilder.Append(" IS NOT NULL"); + } + break; case ExpressionType.Negate: - { - _relationalCommandBuilder.Append("-"); - Visit(sqlUnaryExpression.Operand); - } - - break; + { + _relationalCommandBuilder.Append("-"); + Visit(sqlUnaryExpression.Operand); + } + break; } return sqlUnaryExpression; diff --git a/src/EFCore.Relational/Query/SqlExpressionFactory.cs b/src/EFCore.Relational/Query/SqlExpressionFactory.cs index ce896b2e368..b241b67a34e 100644 --- a/src/EFCore.Relational/Query/SqlExpressionFactory.cs +++ b/src/EFCore.Relational/Query/SqlExpressionFactory.cs @@ -131,22 +131,22 @@ private SqlExpression ApplyTypeMappingOnSqlBinary( case ExpressionType.LessThan: case ExpressionType.LessThanOrEqual: case ExpressionType.NotEqual: - { - inferredTypeMapping = ExpressionExtensions.InferTypeMapping(left, right) - ?? _typeMappingSource.FindMapping(left.Type); - resultType = typeof(bool); - resultTypeMapping = _boolTypeMapping; - } - break; + { + inferredTypeMapping = ExpressionExtensions.InferTypeMapping(left, right) + ?? _typeMappingSource.FindMapping(left.Type); + resultType = typeof(bool); + resultTypeMapping = _boolTypeMapping; + } + break; case ExpressionType.AndAlso: case ExpressionType.OrElse: - { - inferredTypeMapping = _boolTypeMapping; - resultType = typeof(bool); - resultTypeMapping = _boolTypeMapping; - } - break; + { + inferredTypeMapping = _boolTypeMapping; + resultType = typeof(bool); + resultTypeMapping = _boolTypeMapping; + } + break; case ExpressionType.Add: case ExpressionType.Subtract: @@ -156,12 +156,12 @@ private SqlExpression ApplyTypeMappingOnSqlBinary( case ExpressionType.Coalesce: case ExpressionType.And: case ExpressionType.Or: - { - inferredTypeMapping = typeMapping ?? ExpressionExtensions.InferTypeMapping(left, right); - resultType = left.Type; - resultTypeMapping = inferredTypeMapping; - } - break; + { + inferredTypeMapping = typeMapping ?? ExpressionExtensions.InferTypeMapping(left, right); + resultType = left.Type; + resultTypeMapping = inferredTypeMapping; + } + break; default: throw new InvalidOperationException("Incorrect operatorType for SqlBinaryExpression"); diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs index 956a0b8089d..45b339e9b59 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs @@ -551,38 +551,38 @@ public override Expression Visit(Expression expression) return navigationTreeExpression.GetExpression(); case NavigationExpansionExpression navigationExpansionExpression: + { + var pendingSelector = Visit(navigationExpansionExpression.PendingSelector); + Expression result; + var source = Visit(navigationExpansionExpression.Source); + if (pendingSelector == navigationExpansionExpression.CurrentParameter) { - var pendingSelector = Visit(navigationExpansionExpression.PendingSelector); - Expression result; - var source = Visit(navigationExpansionExpression.Source); - if (pendingSelector == navigationExpansionExpression.CurrentParameter) - { - // identity projection - result = source; - } - else - { - var selectorLambda = Expression.Lambda(pendingSelector, navigationExpansionExpression.CurrentParameter); - - result = Expression.Call( - QueryableMethodProvider.SelectMethodInfo.MakeGenericMethod( - navigationExpansionExpression.SourceElementType, - selectorLambda.ReturnType), - source, - Expression.Quote(selectorLambda)); - } - - if (navigationExpansionExpression.CardinalityReducingGenericMethodInfo != null) - { - result = Expression.Call( - navigationExpansionExpression.CardinalityReducingGenericMethodInfo.MakeGenericMethod( - result.Type.TryGetSequenceType()), - result); - } + // identity projection + result = source; + } + else + { + var selectorLambda = Expression.Lambda(pendingSelector, navigationExpansionExpression.CurrentParameter); + + result = Expression.Call( + QueryableMethodProvider.SelectMethodInfo.MakeGenericMethod( + navigationExpansionExpression.SourceElementType, + selectorLambda.ReturnType), + source, + Expression.Quote(selectorLambda)); + } - return result; + if (navigationExpansionExpression.CardinalityReducingGenericMethodInfo != null) + { + result = Expression.Call( + navigationExpansionExpression.CardinalityReducingGenericMethodInfo.MakeGenericMethod( + result.Type.TryGetSequenceType()), + result); } + return result; + } + case OwnedNavigationReference ownedNavigationReference: return Visit(ownedNavigationReference.Parent).CreateEFPropertyExpression(ownedNavigationReference.Navigation); diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs index 5591ee354b4..f8e0e298e2a 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs @@ -1024,19 +1024,19 @@ private Expression SnapshotExpression(Expression selector) return SnapshotExpression(navigationTreeExpression.Value); case NewExpression newExpression: + { + var arguments = new Expression[newExpression.Arguments.Count]; + for (var i = 0; i < newExpression.Arguments.Count; i++) { - var arguments = new Expression[newExpression.Arguments.Count]; - for (var i = 0; i < newExpression.Arguments.Count; i++) - { - arguments[i] = newExpression.Arguments[i] is NewExpression - || newExpression.Arguments[i] is NavigationTreeExpression - ? SnapshotExpression(newExpression.Arguments[i]) - : Expression.Default(newExpression.Arguments[i].Type); - } - - return newExpression.Update(arguments); + arguments[i] = newExpression.Arguments[i] is NewExpression + || newExpression.Arguments[i] is NavigationTreeExpression + ? SnapshotExpression(newExpression.Arguments[i]) + : Expression.Default(newExpression.Arguments[i].Type); } + return newExpression.Update(arguments); + } + case OwnedNavigationReference ownedNavigationReference: return ownedNavigationReference.EntityReference.Clone();