From e3a059b39f49cfa3db688ea1f7f4bacd95042d98 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Thu, 8 Oct 2020 11:53:20 -0700 Subject: [PATCH] Query: Mark entity shaper nullable only when correct (#22533) --- .../Query/SqlExpressions/SelectExpression.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index 98739ab10c3..7c4061e8874 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -1641,9 +1641,10 @@ static void ValidateIdentifyingProjection(SelectExpression selectExpression) if (!innerSelectProjectionExpressions.Contains(innerSelectIdentifier.Column) && (selectExpression.GroupBy.Count == 0 || !selectExpression.GroupBy.Contains(innerSelectIdentifier.Column))) - + { throw new InvalidOperationException(RelationalStrings.MissingIdentifyingProjectionInDistinctGroupBySubquery( innerSelectIdentifier.Column.Table.Alias + "." + innerSelectIdentifier.Column.Name)); + } } } } @@ -2046,7 +2047,10 @@ private Expression AddJoin( } } - innerShaper = new EntityShaperNullableMarkingExpressionVisitor().Visit(innerShaper); + if (innerNullable) + { + innerShaper = new EntityShaperNullableMarkingExpressionVisitor().Visit(innerShaper); + } return New( transparentIdentifierType.GetTypeInfo().DeclaredConstructors.Single(),