diff --git a/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs b/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs
index ad230acc93f..f72a15f02cb 100644
--- a/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs
+++ b/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs
@@ -11,6 +11,8 @@
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal
{
///
@@ -55,7 +57,7 @@ public EntityProjectionExpression(
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
public override Type Type
- => EntityType.ClrType;
+ => EntityType.ClrType!;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -137,7 +139,7 @@ public virtual void AddNavigationBinding([NotNull] INavigation navigation, [NotN
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual EntityShaperExpression BindNavigation([NotNull] INavigation navigation)
+ public virtual EntityShaperExpression? BindNavigation([NotNull] INavigation navigation)
{
if (!EntityType.IsAssignableFrom(navigation.DeclaringEntityType)
&& !navigation.DeclaringEntityType.IsAssignableFrom(EntityType))
diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs
index 16af3723528..77e11725141 100644
--- a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs
+++ b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs
@@ -17,8 +17,11 @@
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+using CA = System.Diagnostics.CodeAnalysis;
using ExpressionExtensions = Microsoft.EntityFrameworkCore.Infrastructure.ExpressionExtensions;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal
{
///
@@ -90,7 +93,7 @@ public InMemoryExpressionTranslatingExpressionVisitor(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual string TranslationErrorDetails { get; private set; }
+ public virtual string? TranslationErrorDetails { get; private set; }
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -118,7 +121,7 @@ protected virtual void AddTranslationErrorDetails([NotNull] string details)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual Expression Translate([NotNull] Expression expression)
+ public virtual Expression? Translate([NotNull] Expression expression)
{
Check.NotNull(expression, nameof(expression));
@@ -127,7 +130,7 @@ public virtual Expression Translate([NotNull] Expression expression)
return TranslateInternal(expression);
}
- private Expression TranslateInternal(Expression expression)
+ private Expression? TranslateInternal(Expression expression)
{
var result = Visit(expression);
@@ -142,7 +145,7 @@ private Expression TranslateInternal(Expression expression)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitBinary(BinaryExpression binaryExpression)
+ protected override Expression? VisitBinary(BinaryExpression binaryExpression)
{
Check.NotNull(binaryExpression, nameof(binaryExpression));
@@ -163,12 +166,12 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
}
if ((binaryExpression.NodeType == ExpressionType.Equal
- || binaryExpression.NodeType == ExpressionType.NotEqual)
+ || binaryExpression.NodeType == ExpressionType.NotEqual)
// Visited expression could be null, We need to pass MemberInitExpression
&& TryRewriteEntityEquality(
binaryExpression.NodeType,
- newLeft ?? binaryExpression.Left,
- newRight ?? binaryExpression.Right,
+ newLeft,
+ newRight,
equalsMethod: false,
out var result))
{
@@ -222,7 +225,7 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitConditional(ConditionalExpression conditionalExpression)
+ protected override Expression? VisitConditional(ConditionalExpression conditionalExpression)
{
Check.NotNull(conditionalExpression, nameof(conditionalExpression));
@@ -258,7 +261,7 @@ protected override Expression VisitConditional(ConditionalExpression conditional
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitExtension(Expression extensionExpression)
+ protected override Expression? VisitExtension(Expression extensionExpression)
{
Check.NotNull(extensionExpression, nameof(extensionExpression));
@@ -294,7 +297,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitInvocation(InvocationExpression invocationExpression)
+ protected override Expression? VisitInvocation(InvocationExpression invocationExpression)
=> null;
///
@@ -303,7 +306,7 @@ protected override Expression VisitInvocation(InvocationExpression invocationExp
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitLambda(Expression lambdaExpression)
+ protected override Expression? VisitLambda(Expression lambdaExpression)
=> null;
///
@@ -312,7 +315,7 @@ protected override Expression VisitLambda(Expression lambdaExpression)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitListInit(ListInitExpression listInitExpression)
+ protected override Expression? VisitListInit(ListInitExpression listInitExpression)
=> null;
///
@@ -321,7 +324,7 @@ protected override Expression VisitListInit(ListInitExpression listInitExpressio
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitMember(MemberExpression memberExpression)
+ protected override Expression? VisitMember(MemberExpression memberExpression)
{
Check.NotNull(memberExpression, nameof(memberExpression));
@@ -364,7 +367,7 @@ static bool ShouldApplyNullProtectionForMemberAccess(Type callerType, string mem
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override MemberAssignment VisitMemberAssignment(MemberAssignment memberAssignment)
+ protected override MemberAssignment? VisitMemberAssignment(MemberAssignment memberAssignment)
{
var expression = Visit(memberAssignment.Expression);
if (expression == null)
@@ -386,7 +389,7 @@ protected override MemberAssignment VisitMemberAssignment(MemberAssignment membe
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)
+ protected override Expression? VisitMethodCall(MethodCallExpression methodCallExpression)
{
Check.NotNull(methodCallExpression, nameof(methodCallExpression));
@@ -417,7 +420,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
if (methodCallExpression.Arguments[0].Type.TryGetElementType(typeof(IQueryable<>)) == null
&& Visit(methodCallExpression.Arguments[0]) is GroupingElementExpression groupingElementExpression)
{
- Expression result = null;
+ Expression? result = null;
switch (methodCallExpression.Method.Name)
{
case nameof(Enumerable.Average):
@@ -433,7 +436,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
result = expression == null
? null
: Expression.Call(
- EnumerableMethods.GetAverageWithoutSelector(expression.Type.TryGetSequenceType()), expression);
+ EnumerableMethods.GetAverageWithoutSelector(expression.Type.TryGetSequenceType()!), expression);
break;
}
@@ -441,14 +444,16 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
{
if (methodCallExpression.Arguments.Count == 2)
{
- groupingElementExpression = ApplyPredicate(
+ var temporaryGroupingElementExpression = ApplyPredicate(
groupingElementExpression, methodCallExpression.Arguments[1].UnwrapLambdaFromQuote());
- if (groupingElementExpression == null)
+ if (temporaryGroupingElementExpression == null)
{
result = null;
break;
}
+
+ groupingElementExpression = temporaryGroupingElementExpression;
}
var expression = ApplySelect(groupingElementExpression);
@@ -473,14 +478,16 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
{
if (methodCallExpression.Arguments.Count == 2)
{
- groupingElementExpression = ApplyPredicate(
+ var temporaryGroupingElementExpression = ApplyPredicate(
groupingElementExpression, methodCallExpression.Arguments[1].UnwrapLambdaFromQuote());
- if (groupingElementExpression == null)
+ if (temporaryGroupingElementExpression == null)
{
result = null;
break;
}
+
+ groupingElementExpression = temporaryGroupingElementExpression;
}
var expression = ApplySelect(groupingElementExpression);
@@ -509,7 +516,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
}
else
{
- var type = expression.Type.TryGetSequenceType();
+ var type = expression.Type.TryGetSequenceType()!;
var aggregateMethod = EnumerableMethods.GetMaxWithoutSelector(type);
if (aggregateMethod.IsGenericMethod)
{
@@ -538,7 +545,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
}
else
{
- var type = expression.Type.TryGetSequenceType();
+ var type = expression.Type.TryGetSequenceType()!;
var aggregateMethod = EnumerableMethods.GetMinWithoutSelector(type);
if (aggregateMethod.IsGenericMethod)
{
@@ -568,7 +575,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
result = expression == null
? null
: Expression.Call(
- EnumerableMethods.GetSumWithoutSelector(expression.Type.TryGetSequenceType()), expression);
+ EnumerableMethods.GetSumWithoutSelector(expression.Type.TryGetSequenceType()!), expression);
break;
}
@@ -583,7 +590,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
return result ?? throw new InvalidOperationException(CoreStrings.TranslationFailed(methodCallExpression.Print()));
- GroupingElementExpression ApplyPredicate(GroupingElementExpression groupingElement, LambdaExpression lambdaExpression)
+ GroupingElementExpression? ApplyPredicate(GroupingElementExpression groupingElement, LambdaExpression lambdaExpression)
{
var predicate = TranslateInternal(RemapLambda(groupingElement, lambdaExpression));
@@ -596,7 +603,7 @@ GroupingElementExpression ApplyPredicate(GroupingElementExpression groupingEleme
Expression.Lambda(predicate, groupingElement.ValueBufferParameter)));
}
- Expression ApplySelect(GroupingElementExpression groupingElement)
+ Expression? ApplySelect(GroupingElementExpression groupingElement)
{
var selector = TranslateInternal(groupingElement.Selector);
@@ -649,7 +656,7 @@ static Expression RemapLambda(GroupingElementExpression groupingElement, LambdaE
var shaperExpression = subqueryTranslation.ShaperExpression;
var innerExpression = shaperExpression;
- Type convertedType = null;
+ Type? convertedType = null;
if (shaperExpression is UnaryExpression unaryExpression
&& unaryExpression.NodeType == ExpressionType.Convert)
{
@@ -671,6 +678,12 @@ static Expression RemapLambda(GroupingElementExpression groupingElement, LambdaE
return null;
}
+ if (projectionBindingExpression.ProjectionMember == null)
+ {
+ // We don't lift scalar subquery with client eval
+ return null;
+ }
+
return ProcessSingleResultScalar(
subquery.ServerQueryExpression,
subquery.GetMappedProjection(projectionBindingExpression.ProjectionMember),
@@ -699,7 +712,7 @@ static Expression RemapLambda(GroupingElementExpression groupingElement, LambdaE
return Expression.Call(_inMemoryLikeMethodInfo, visitedArguments);
}
- Expression @object = null;
+ Expression? @object = null;
Expression[] arguments;
var method = methodCallExpression.Method;
@@ -840,7 +853,7 @@ static Expression RemapLambda(GroupingElementExpression groupingElement, LambdaE
// if object is nullable, add null safeguard before calling the function
// we special-case Nullable<>.GetValueOrDefault, which doesn't need the safeguard
if (methodCallExpression.Object != null
- && @object.Type.IsNullableType()
+ && @object!.Type.IsNullableType()
&& methodCallExpression.Method.Name != nameof(Nullable.GetValueOrDefault))
{
var result = (Expression)methodCallExpression.Update(
@@ -865,7 +878,7 @@ static Expression RemapLambda(GroupingElementExpression groupingElement, LambdaE
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitNew(NewExpression newExpression)
+ protected override Expression? VisitNew(NewExpression newExpression)
{
Check.NotNull(newExpression, nameof(newExpression));
@@ -895,7 +908,7 @@ protected override Expression VisitNew(NewExpression newExpression)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitNewArray(NewArrayExpression newArrayExpression)
+ protected override Expression? VisitNewArray(NewArrayExpression newArrayExpression)
{
Check.NotNull(newArrayExpression, nameof(newArrayExpression));
@@ -925,7 +938,7 @@ protected override Expression VisitNewArray(NewArrayExpression newArrayExpressio
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitParameter(ParameterExpression parameterExpression)
+ protected override Expression? VisitParameter(ParameterExpression parameterExpression)
{
Check.NotNull(parameterExpression, nameof(parameterExpression));
@@ -946,7 +959,7 @@ protected override Expression VisitParameter(ParameterExpression parameterExpres
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitTypeBinary(TypeBinaryExpression typeBinaryExpression)
+ protected override Expression? VisitTypeBinary(TypeBinaryExpression typeBinaryExpression)
{
Check.NotNull(typeBinaryExpression, nameof(typeBinaryExpression));
@@ -963,9 +976,11 @@ protected override Expression VisitTypeBinary(TypeBinaryExpression typeBinaryExp
var derivedType = entityType.GetDerivedTypes().SingleOrDefault(et => et.ClrType == typeBinaryExpression.TypeOperand);
if (derivedType != null)
{
- var discriminatorProperty = entityType.GetDiscriminatorProperty();
+ // All hierarchies have discriminator property
+ var discriminatorProperty = entityType.GetDiscriminatorProperty()!;
var boundProperty = BindProperty(entityReferenceExpression, discriminatorProperty, discriminatorProperty.ClrType);
- var valueComparer = discriminatorProperty.GetKeyValueComparer();
+ // KeyValueComparer is not null at runtime
+ var valueComparer = discriminatorProperty.GetKeyValueComparer()!;
var equals = valueComparer.ExtractEqualsBody(
boundProperty,
@@ -993,7 +1008,7 @@ protected override Expression VisitTypeBinary(TypeBinaryExpression typeBinaryExp
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitUnary(UnaryExpression unaryExpression)
+ protected override Expression? VisitUnary(UnaryExpression unaryExpression)
{
Check.NotNull(unaryExpression, nameof(unaryExpression));
@@ -1048,7 +1063,7 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression)
return result;
}
- private Expression TryBindMember(Expression source, MemberIdentity member, Type type)
+ private Expression? TryBindMember(Expression source, MemberIdentity member, Type type)
{
if (!(source is EntityReferenceExpression entityReferenceExpression))
{
@@ -1074,7 +1089,7 @@ private Expression TryBindMember(Expression source, MemberIdentity member, Type
return null;
}
- private Expression BindProperty(EntityReferenceExpression entityReferenceExpression, IProperty property, Type type)
+ private Expression? BindProperty(EntityReferenceExpression entityReferenceExpression, IProperty property, Type type)
{
if (entityReferenceExpression.ParameterEntity != null)
{
@@ -1110,7 +1125,7 @@ private Expression BindProperty(EntityReferenceExpression entityReferenceExpress
else
{
// This has to be index map since entities cannot map to just integer index
- var index = projectionBindingExpression.IndexMap[property];
+ var index = projectionBindingExpression.IndexMap![property];
readValueExpression = inMemoryQueryExpression.Projection[index];
}
@@ -1176,7 +1191,7 @@ private static Expression ConvertToNonNullable(Expression expression)
? Expression.Convert(expression, expression.Type.UnwrapNullableType())
: expression;
- private IProperty FindProperty(Expression expression)
+ private IProperty? FindProperty(Expression expression)
{
if (expression.NodeType == ExpressionType.Convert
&& expression.Type.IsNullableType()
@@ -1196,7 +1211,7 @@ private IProperty FindProperty(Expression expression)
return null;
}
- private bool TryRewriteContainsEntity(Expression source, Expression item, out Expression result)
+ private bool TryRewriteContainsEntity(Expression source, Expression item, [CA.NotNullWhen(true)] out Expression? result)
{
result = null;
@@ -1251,7 +1266,7 @@ when methodCallExpression.Method.IsGenericMethod
var newParameterName =
$"{_runtimeParameterPrefix}"
- + $"{parameterName.Substring(QueryCompilationContext.QueryParameterPrefix.Length)}_{property.Name}";
+ + $"{parameterName[QueryCompilationContext.QueryParameterPrefix.Length..]}_{property.Name}";
rewrittenSource = _queryCompilationContext.RegisterRuntimeParameter(newParameterName, lambda);
break;
@@ -1269,7 +1284,8 @@ when methodCallExpression.Method.IsGenericMethod
return true;
}
- private bool TryRewriteEntityEquality(ExpressionType nodeType, Expression left, Expression right, bool equalsMethod, out Expression result)
+ private bool TryRewriteEntityEquality(
+ ExpressionType nodeType, Expression left, Expression right, bool equalsMethod, [CA.NotNullWhen(true)] out Expression? result)
{
var leftEntityReference = left as EntityReferenceExpression;
var rightEntityReference = right as EntityReferenceExpression;
@@ -1284,7 +1300,7 @@ private bool TryRewriteEntityEquality(ExpressionType nodeType, Expression left,
if (IsNullConstantExpression(left)
|| IsNullConstantExpression(right))
{
- var nonNullEntityReference = IsNullConstantExpression(left) ? rightEntityReference : leftEntityReference;
+ var nonNullEntityReference = (IsNullConstantExpression(left) ? rightEntityReference : leftEntityReference)!;
var entityType1 = nonNullEntityReference.EntityType;
var primaryKeyProperties1 = entityType1.FindPrimaryKey()?.Properties;
if (primaryKeyProperties1 == null)
@@ -1376,7 +1392,7 @@ when methodCallExpression.Method.IsGenericMethod
var newParameterName =
$"{_runtimeParameterPrefix}"
- + $"{parameterName.Substring(QueryCompilationContext.QueryParameterPrefix.Length)}_{property.Name}";
+ + $"{parameterName[QueryCompilationContext.QueryParameterPrefix.Length..]}_{property.Name}";
return _queryCompilationContext.RegisterRuntimeParameter(newParameterName, lambda);
@@ -1400,12 +1416,15 @@ when CanEvaluate(memberInitExpression):
}
}
+#nullable disable
+ // Need unconstrainted nullable T
private static T ParameterValueExtractor(QueryContext context, string baseParameterName, IProperty property)
{
var baseParameter = context.ParameterValues[baseParameterName];
return baseParameter == null ? (T)(object)null : (T)property.GetGetter().GetClrValue(baseParameter);
}
+ // Need unconstrainted nullable TProperty
private static List ParameterListValueExtractor(
QueryContext context,
string baseParameterName,
@@ -1419,6 +1438,7 @@ private static List ParameterListValueExtractor(
var getter = property.GetGetter();
return baseListParameter.Select(e => e != null ? (TProperty)getter.GetClrValue(e) : (TProperty)(object)null).ToList();
}
+#nullable enable
private static ConstantExpression GetValue(Expression expression)
=> Expression.Constant(
@@ -1483,10 +1503,10 @@ private static bool IsNullConstantExpression(Expression expression)
=> expression is ConstantExpression constantExpression && constantExpression.Value == null;
[DebuggerStepThrough]
- private static bool TranslationFailed(Expression original, Expression translation)
- => original != null && (translation == null || translation is EntityReferenceExpression);
+ private static bool TranslationFailed(Expression? original, Expression? translation)
+ => original != null && TranslationFailed(translation);
- private static bool TranslationFailed(Expression translation)
+ private static bool TranslationFailed([CA.NotNullWhen(false)] Expression? translation)
=> translation == null || translation is EntityReferenceExpression;
private static bool InMemoryLike(string matchExpression, string pattern, string escapeCharacter)
@@ -1621,17 +1641,18 @@ private EntityReferenceExpression(EntityReferenceExpression entityReferenceExpre
EntityType = entityType;
}
- public EntityShaperExpression ParameterEntity { get; }
- public ShapedQueryExpression SubqueryEntity { get; }
+ public EntityShaperExpression? ParameterEntity { get; }
+ public ShapedQueryExpression? SubqueryEntity { get; }
public IEntityType EntityType { get; }
public override Type Type
- => EntityType.ClrType;
+ // No shadow entities at runtime
+ => EntityType.ClrType!;
public override ExpressionType NodeType
=> ExpressionType.Extension;
- public Expression Convert(Type type)
+ public Expression? Convert(Type type)
{
if (type == typeof(object) // Ignore object conversion
|| type.IsAssignableFrom(Type)) // Ignore casting to base type/interface
diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs
index 0e1ae7ce05c..01ba22955e7 100644
--- a/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs
+++ b/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs
@@ -13,6 +13,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal
{
///
@@ -46,6 +48,7 @@ public InMemoryProjectionBindingExpressionVisitor(
{
_queryableMethodTranslatingExpressionVisitor = queryableMethodTranslatingExpressionVisitor;
_expressionTranslatingExpressionVisitor = expressionTranslatingExpressionVisitor;
+ _queryExpression = null!;
}
///
@@ -75,11 +78,11 @@ public virtual Expression Translate([NotNull] InMemoryQueryExpression queryExpre
}
_queryExpression.ReplaceProjectionMapping(_projectionMapping);
- _queryExpression = null;
+ _queryExpression = null!;
_projectionMapping.Clear();
_projectionMembers.Clear();
- result = MatchTypes(result, expression.Type);
+ result = MatchTypes(result!, expression.Type);
return result;
}
@@ -90,7 +93,7 @@ public virtual Expression Translate([NotNull] InMemoryQueryExpression queryExpre
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public override Expression Visit(Expression expression)
+ public override Expression? Visit(Expression? expression)
{
if (expression == null)
{
@@ -120,9 +123,9 @@ public override Expression Visit(Expression expression)
case MaterializeCollectionNavigationExpression materializeCollectionNavigationExpression:
return AddCollectionProjection(
_queryableMethodTranslatingExpressionVisitor.TranslateSubquery(
- materializeCollectionNavigationExpression.Subquery),
+ materializeCollectionNavigationExpression.Subquery)!,
materializeCollectionNavigationExpression.Navigation,
- materializeCollectionNavigationExpression.Navigation.ClrType.TryGetSequenceType());
+ materializeCollectionNavigationExpression.Navigation.ClrType.TryGetSequenceType()!);
case MethodCallExpression methodCallExpression:
{
@@ -196,8 +199,8 @@ public override Expression Visit(Expression expression)
///
protected override Expression VisitBinary(BinaryExpression binaryExpression)
{
- var left = MatchTypes(Visit(binaryExpression.Left), binaryExpression.Left.Type);
- var right = MatchTypes(Visit(binaryExpression.Right), binaryExpression.Right.Type);
+ var left = MatchTypes(Visit(binaryExpression.Left)!, binaryExpression.Left.Type);
+ var right = MatchTypes(Visit(binaryExpression.Right)!, binaryExpression.Right.Type);
return binaryExpression.Update(left, VisitAndConvert(binaryExpression.Conversion, "VisitBinary"), right);
}
@@ -210,9 +213,9 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
///
protected override Expression VisitConditional(ConditionalExpression conditionalExpression)
{
- var test = Visit(conditionalExpression.Test);
- var ifTrue = Visit(conditionalExpression.IfTrue);
- var ifFalse = Visit(conditionalExpression.IfFalse);
+ var test = Visit(conditionalExpression.Test)!;
+ var ifTrue = Visit(conditionalExpression.IfTrue)!;
+ var ifFalse = Visit(conditionalExpression.IfFalse)!;
if (test.Type == typeof(bool?))
{
@@ -228,7 +231,7 @@ protected override Expression VisitConditional(ConditionalExpression conditional
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitExtension(Expression extensionExpression)
+ protected override Expression? VisitExtension(Expression extensionExpression)
{
Check.NotNull(extensionExpression, nameof(extensionExpression));
@@ -237,6 +240,12 @@ protected override Expression VisitExtension(Expression extensionExpression)
EntityProjectionExpression entityProjectionExpression;
if (entityShaperExpression.ValueBufferExpression is ProjectionBindingExpression projectionBindingExpression)
{
+ if (projectionBindingExpression.ProjectionMember == null)
+ {
+ // We don't process binding with client projection
+ return null;
+ }
+
entityProjectionExpression = (EntityProjectionExpression)((InMemoryQueryExpression)projectionBindingExpression.QueryExpression)
.GetMappedProjection(projectionBindingExpression.ProjectionMember);
}
@@ -274,7 +283,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
protected override ElementInit VisitElementInit(ElementInit elementInit)
- => elementInit.Update(elementInit.Arguments.Select(e => MatchTypes(Visit(e), e.Type)));
+ => elementInit.Update(elementInit.Arguments.Select(e => MatchTypes(Visit(e)!, e.Type)));
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -311,10 +320,10 @@ protected override Expression VisitMember(MemberExpression memberExpression)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override MemberAssignment VisitMemberAssignment(MemberAssignment memberAssignment)
+ protected override MemberAssignment? VisitMemberAssignment(MemberAssignment memberAssignment)
{
var expression = memberAssignment.Expression;
- Expression visitedExpression;
+ Expression? visitedExpression;
if (_clientEval)
{
visitedExpression = Visit(memberAssignment.Expression);
@@ -333,7 +342,7 @@ protected override MemberAssignment VisitMemberAssignment(MemberAssignment membe
_projectionMembers.Pop();
}
- visitedExpression = MatchTypes(visitedExpression, expression.Type);
+ visitedExpression = MatchTypes(visitedExpression!, expression.Type);
return memberAssignment.Update(visitedExpression);
}
@@ -344,7 +353,7 @@ protected override MemberAssignment VisitMemberAssignment(MemberAssignment membe
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitMemberInit(MemberInitExpression memberInitExpression)
+ protected override Expression? VisitMemberInit(MemberInitExpression memberInitExpression)
{
Check.NotNull(memberInitExpression, nameof(memberInitExpression));
@@ -385,7 +394,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
for (var i = 0; i < methodCallExpression.Arguments.Count; i++)
{
var argument = methodCallExpression.Arguments[i];
- arguments[i] = MatchTypes(Visit(argument), argument.Type);
+ arguments[i] = MatchTypes(Visit(argument)!, argument.Type);
}
Expression updatedMethodCallExpression = methodCallExpression.Update(
@@ -416,7 +425,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitNew(NewExpression newExpression)
+ protected override Expression? VisitNew(NewExpression newExpression)
{
Check.NotNull(newExpression, nameof(newExpression));
@@ -435,7 +444,7 @@ protected override Expression VisitNew(NewExpression newExpression)
for (var i = 0; i < newArguments.Length; i++)
{
var argument = newExpression.Arguments[i];
- Expression visitedArgument;
+ Expression? visitedArgument;
if (_clientEval)
{
visitedArgument = Visit(argument);
@@ -453,7 +462,7 @@ protected override Expression VisitNew(NewExpression newExpression)
_projectionMembers.Pop();
}
- newArguments[i] = MatchTypes(visitedArgument, argument.Type);
+ newArguments[i] = MatchTypes(visitedArgument!, argument.Type);
}
return newExpression.Update(newArguments);
@@ -466,7 +475,7 @@ protected override Expression VisitNew(NewExpression newExpression)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
protected override Expression VisitNewArray(NewArrayExpression newArrayExpression)
- => newArrayExpression.Update(newArrayExpression.Expressions.Select(e => MatchTypes(Visit(e), e.Type)));
+ => newArrayExpression.Update(newArrayExpression.Expressions.Select(e => MatchTypes(Visit(e)!, e.Type)));
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -476,7 +485,7 @@ protected override Expression VisitNewArray(NewArrayExpression newArrayExpressio
///
protected override Expression VisitUnary(UnaryExpression unaryExpression)
{
- var operand = Visit(unaryExpression.Operand);
+ var operand = Visit(unaryExpression.Operand)!;
return (unaryExpression.NodeType == ExpressionType.Convert
|| unaryExpression.NodeType == ExpressionType.ConvertChecked)
@@ -487,7 +496,7 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression)
private CollectionShaperExpression AddCollectionProjection(
ShapedQueryExpression subquery,
- INavigationBase navigation,
+ INavigationBase? navigation,
Type elementType)
=> new CollectionShaperExpression(
new ProjectionBindingExpression(
diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.ResultEnumerable.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.ResultEnumerable.cs
index 4f4f92e5610..fa2f2eb8585 100644
--- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.ResultEnumerable.cs
+++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.ResultEnumerable.cs
@@ -6,6 +6,8 @@
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Storage;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal
{
public partial class InMemoryQueryExpression
diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs
index fb7a2a589c7..b0656bb5bd3 100644
--- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs
+++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs
@@ -16,6 +16,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using ExpressionExtensions = Microsoft.EntityFrameworkCore.Infrastructure.ExpressionExtensions;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal
{
///
@@ -40,7 +42,7 @@ private readonly IDictionary _projectionMapping = new Dictionary();
- private ParameterExpression _groupingParameter;
+ private ParameterExpression? _groupingParameter;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -98,6 +100,7 @@ public InMemoryQueryExpression([NotNull] IEntityType entityType)
ServerQueryExpression = new InMemoryTableExpression(entityType);
var readExpressionMap = new Dictionary();
var discriminatorProperty = entityType.GetDiscriminatorProperty();
+ var keyValueComparer = discriminatorProperty?.GetKeyValueComparer();
foreach (var property in entityType.GetAllBaseTypesInclusive().SelectMany(et => et.GetDeclaredProperties()))
{
readExpressionMap[property] = CreateReadValueExpression(property.ClrType, property.GetIndex(), property);
@@ -107,9 +110,9 @@ public InMemoryQueryExpression([NotNull] IEntityType entityType)
{
var entityCheck = derivedEntityType.GetConcreteDerivedTypesInclusive()
.Select(
- e => discriminatorProperty.GetKeyValueComparer().ExtractEqualsBody(
- readExpressionMap[discriminatorProperty],
- Constant(e.GetDiscriminatorValue(), discriminatorProperty.ClrType)))
+ e => keyValueComparer!.ExtractEqualsBody(
+ readExpressionMap[discriminatorProperty!],
+ Constant(e.GetDiscriminatorValue(), discriminatorProperty!.ClrType)))
.Aggregate((l, r) => OrElse(l, r));
foreach (var property in derivedEntityType.GetDeclaredProperties())
@@ -436,7 +439,7 @@ public virtual void ApplyDefaultIfEmpty()
_valueBufferSlots.Clear();
}
- private static IPropertyBase InferPropertyFromInner(Expression expression)
+ private static IPropertyBase? InferPropertyFromInner(Expression expression)
=> expression is MethodCallExpression methodCallExpression
&& methodCallExpression.Method.IsGenericMethod
&& methodCallExpression.Method.GetGenericMethodDefinition() == ExpressionExtensions.ValueBufferTryReadValueMethod
@@ -576,7 +579,7 @@ private Expression GetGroupingKey(Expression key, List groupingExpre
}
}
- private Expression CreateReadValueExpression(Type type, int index, IPropertyBase property)
+ private Expression CreateReadValueExpression(Type type, int index, IPropertyBase? property)
=> _valueBufferParameter.CreateValueBufferReadValueExpression(type, index, property);
///
diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs
index 489dcae9b15..ac691d0d4da 100644
--- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs
+++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs
@@ -9,12 +9,13 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.InMemory.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal
{
///
@@ -78,7 +79,7 @@ protected override QueryableMethodTranslatingExpressionVisitor CreateSubqueryVis
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)
+ protected override Expression? VisitMethodCall(MethodCallExpression methodCallExpression)
{
if (methodCallExpression.Method.IsGenericMethod
&& methodCallExpression.Arguments.Count == 1
@@ -102,7 +103,8 @@ protected override ShapedQueryExpression CreateShapedQueryExpression(Type elemen
{
Check.NotNull(elementType, nameof(elementType));
- return CreateShapedQueryExpression(_model.FindEntityType(elementType));
+ // Let it throw if null found.
+ return CreateShapedQueryExpression(_model.FindEntityType(elementType)!);
}
///
@@ -135,17 +137,18 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateAll(ShapedQueryExpression source, LambdaExpression predicate)
+ protected override ShapedQueryExpression? TranslateAll(ShapedQueryExpression source, LambdaExpression predicate)
{
Check.NotNull(source, nameof(source));
Check.NotNull(predicate, nameof(predicate));
predicate = Expression.Lambda(Expression.Not(predicate.Body), predicate.Parameters);
- source = TranslateWhere(source, predicate);
- if (source == null)
+ var newSource = TranslateWhere(source, predicate);
+ if (newSource == null)
{
return null;
}
+ source = newSource;
var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression;
@@ -170,15 +173,16 @@ protected override ShapedQueryExpression TranslateAll(ShapedQueryExpression sour
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateAny(ShapedQueryExpression source, LambdaExpression predicate)
+ protected override ShapedQueryExpression? TranslateAny(ShapedQueryExpression source, LambdaExpression? predicate)
{
if (predicate != null)
{
- source = TranslateWhere(source, predicate);
- if (source == null)
+ var newSource = TranslateWhere(source, predicate);
+ if (newSource == null)
{
return null;
}
+ source = newSource;
}
var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression;
@@ -203,7 +207,7 @@ protected override ShapedQueryExpression TranslateAny(ShapedQueryExpression sour
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateAverage(ShapedQueryExpression source, LambdaExpression selector, Type resultType)
+ protected override ShapedQueryExpression? TranslateAverage(ShapedQueryExpression source, LambdaExpression? selector, Type resultType)
{
Check.NotNull(source, nameof(source));
Check.NotNull(resultType, nameof(resultType));
@@ -217,7 +221,7 @@ protected override ShapedQueryExpression TranslateAverage(ShapedQueryExpression
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression source, Type resultType)
+ protected override ShapedQueryExpression? TranslateCast(ShapedQueryExpression source, Type resultType)
{
Check.NotNull(source, nameof(source));
Check.NotNull(resultType, nameof(resultType));
@@ -233,7 +237,7 @@ protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression sou
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2)
+ protected override ShapedQueryExpression? TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
Check.NotNull(source1, nameof(source1));
Check.NotNull(source2, nameof(source2));
@@ -247,18 +251,20 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateContains(ShapedQueryExpression source, Expression item)
+ protected override ShapedQueryExpression? TranslateContains(ShapedQueryExpression source, Expression item)
{
Check.NotNull(source, nameof(source));
Check.NotNull(item, nameof(item));
var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression;
- item = TranslateExpression(item, preserveType: true);
- if (item == null)
+ var newItem = TranslateExpression(item, preserveType: true);
+ if (newItem == null)
{
return null;
}
+ item = newItem;
+
inMemoryQueryExpression.UpdateServerQueryExpression(
Expression.Call(
EnumerableMethods.Contains.MakeGenericMethod(item.Type),
@@ -278,17 +284,18 @@ protected override ShapedQueryExpression TranslateContains(ShapedQueryExpression
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression source, LambdaExpression predicate)
+ protected override ShapedQueryExpression? TranslateCount(ShapedQueryExpression source, LambdaExpression? predicate)
{
Check.NotNull(source, nameof(source));
if (predicate != null)
{
- source = TranslateWhere(source, predicate);
- if (source == null)
+ var newSource = TranslateWhere(source, predicate);
+ if (newSource == null)
{
return null;
}
+ source = newSource;
}
var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression;
@@ -313,7 +320,7 @@ protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression so
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateDefaultIfEmpty(ShapedQueryExpression source, Expression defaultValue)
+ protected override ShapedQueryExpression? TranslateDefaultIfEmpty(ShapedQueryExpression source, Expression? defaultValue)
{
Check.NotNull(source, nameof(source));
@@ -332,7 +339,7 @@ protected override ShapedQueryExpression TranslateDefaultIfEmpty(ShapedQueryExpr
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateDistinct(ShapedQueryExpression source)
+ protected override ShapedQueryExpression? TranslateDistinct(ShapedQueryExpression source)
{
Check.NotNull(source, nameof(source));
@@ -353,7 +360,7 @@ protected override ShapedQueryExpression TranslateDistinct(ShapedQueryExpression
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateElementAtOrDefault(
+ protected override ShapedQueryExpression? TranslateElementAtOrDefault(
ShapedQueryExpression source,
Expression index,
bool returnDefault)
@@ -370,7 +377,7 @@ protected override ShapedQueryExpression TranslateElementAtOrDefault(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2)
+ protected override ShapedQueryExpression? TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
Check.NotNull(source1, nameof(source1));
Check.NotNull(source2, nameof(source2));
@@ -384,9 +391,9 @@ protected override ShapedQueryExpression TranslateExcept(ShapedQueryExpression s
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateFirstOrDefault(
+ protected override ShapedQueryExpression? TranslateFirstOrDefault(
ShapedQueryExpression source,
- LambdaExpression predicate,
+ LambdaExpression? predicate,
Type returnType,
bool returnDefault)
{
@@ -408,11 +415,11 @@ protected override ShapedQueryExpression TranslateFirstOrDefault(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateGroupBy(
+ protected override ShapedQueryExpression? TranslateGroupBy(
ShapedQueryExpression source,
LambdaExpression keySelector,
- LambdaExpression elementSelector,
- LambdaExpression resultSelector)
+ LambdaExpression? elementSelector,
+ LambdaExpression? resultSelector)
{
Check.NotNull(source, nameof(source));
Check.NotNull(keySelector, nameof(keySelector));
@@ -452,7 +459,7 @@ protected override ShapedQueryExpression TranslateGroupBy(
return null;
}
- private Expression TranslateGroupingKey(Expression expression)
+ private Expression? TranslateGroupingKey(Expression expression)
{
switch (expression)
{
@@ -462,7 +469,7 @@ private Expression TranslateGroupingKey(Expression expression)
return newExpression;
}
- var newArguments = new Expression[newExpression.Arguments.Count];
+ var newArguments = new Expression?[newExpression.Arguments.Count];
for (var i = 0; i < newArguments.Length; i++)
{
newArguments[i] = TranslateGroupingKey(newExpression.Arguments[i]);
@@ -475,7 +482,7 @@ private Expression TranslateGroupingKey(Expression expression)
return newExpression.Update(newArguments);
case MemberInitExpression memberInitExpression:
- var updatedNewExpression = (NewExpression)TranslateGroupingKey(memberInitExpression.NewExpression);
+ var updatedNewExpression = (NewExpression?)TranslateGroupingKey(memberInitExpression.NewExpression);
if (updatedNewExpression == null)
{
return null;
@@ -515,7 +522,7 @@ private Expression TranslateGroupingKey(Expression expression)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateGroupJoin(
+ protected override ShapedQueryExpression? TranslateGroupJoin(
ShapedQueryExpression outer,
ShapedQueryExpression inner,
LambdaExpression outerKeySelector,
@@ -537,7 +544,7 @@ protected override ShapedQueryExpression TranslateGroupJoin(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2)
+ protected override ShapedQueryExpression? TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
Check.NotNull(source1, nameof(source1));
Check.NotNull(source2, nameof(source2));
@@ -551,7 +558,7 @@ protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpressio
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateJoin(
+ protected override ShapedQueryExpression? TranslateJoin(
ShapedQueryExpression outer,
ShapedQueryExpression inner,
LambdaExpression outerKeySelector,
@@ -564,13 +571,14 @@ protected override ShapedQueryExpression TranslateJoin(
Check.NotNull(innerKeySelector, nameof(innerKeySelector));
Check.NotNull(resultSelector, nameof(resultSelector));
- (outerKeySelector, innerKeySelector) = ProcessJoinKeySelector(outer, inner, outerKeySelector, innerKeySelector);
+ var (newOuterKeySelector, newInnerKeySelector) = ProcessJoinKeySelector(outer, inner, outerKeySelector, innerKeySelector);
- if (outerKeySelector == null
- || innerKeySelector == null)
+ if (newOuterKeySelector == null
+ || newInnerKeySelector == null)
{
return null;
}
+ (outerKeySelector, innerKeySelector) = (newOuterKeySelector, newInnerKeySelector);
var transparentIdentifierType = TransparentIdentifierFactory.Create(
resultSelector.Parameters[0].Type,
@@ -591,7 +599,7 @@ protected override ShapedQueryExpression TranslateJoin(
#pragma warning restore CS0618 // Type or member is obsolete
}
- private (LambdaExpression OuterKeySelector, LambdaExpression InnerKeySelector) ProcessJoinKeySelector(
+ private (LambdaExpression? OuterKeySelector, LambdaExpression? InnerKeySelector) ProcessJoinKeySelector(
ShapedQueryExpression outer,
ShapedQueryExpression inner,
LambdaExpression outerKeySelector,
@@ -616,7 +624,7 @@ protected override ShapedQueryExpression TranslateJoin(
return AlignKeySelectorTypes(outerKeySelector, innerKeySelector);
}
- private static (Expression, Expression) DecomposeJoinCondition(Expression joinCondition)
+ private static (Expression?, Expression?) DecomposeJoinCondition(Expression? joinCondition)
{
var leftExpressions = new List();
var rightExpressions = new List();
@@ -630,17 +638,14 @@ private static (Expression, Expression) DecomposeJoinCondition(Expression joinCo
// InMemory joins need to use AnonymousObject to perform correct key comparison for server side joins
static Expression CreateAnonymousObject(List expressions)
=> Expression.New(
-#pragma warning disable EF1001 // Internal EF Core API usage.
- // #20565
AnonymousObject.AnonymousObjectCtor,
-#pragma warning restore EF1001 // Internal EF Core API usage.
Expression.NewArrayInit(
typeof(object),
expressions.Select(e => Expression.Convert(e, typeof(object)))));
}
private static bool ProcessJoinCondition(
- Expression joinCondition,
+ Expression? joinCondition,
List leftExpressions,
List rightExpressions)
{
@@ -695,9 +700,9 @@ static bool IsConvertedToNullable(Expression outer, Expression inner)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateLastOrDefault(
+ protected override ShapedQueryExpression? TranslateLastOrDefault(
ShapedQueryExpression source,
- LambdaExpression predicate,
+ LambdaExpression? predicate,
Type returnType,
bool returnDefault)
{
@@ -719,7 +724,7 @@ protected override ShapedQueryExpression TranslateLastOrDefault(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateLeftJoin(
+ protected override ShapedQueryExpression? TranslateLeftJoin(
ShapedQueryExpression outer,
ShapedQueryExpression inner,
LambdaExpression outerKeySelector,
@@ -732,14 +737,16 @@ protected override ShapedQueryExpression TranslateLeftJoin(
Check.NotNull(innerKeySelector, nameof(innerKeySelector));
Check.NotNull(resultSelector, nameof(resultSelector));
- (outerKeySelector, innerKeySelector) = ProcessJoinKeySelector(outer, inner, outerKeySelector, innerKeySelector);
+ var (newOuterKeySelector, newInnerKeySelector) = ProcessJoinKeySelector(outer, inner, outerKeySelector, innerKeySelector);
- if (outerKeySelector == null
- || innerKeySelector == null)
+ if (newOuterKeySelector == null
+ || newInnerKeySelector == null)
{
return null;
}
+ (outerKeySelector, innerKeySelector) = (newOuterKeySelector, newInnerKeySelector);
+
var transparentIdentifierType = TransparentIdentifierFactory.Create(
resultSelector.Parameters[0].Type,
resultSelector.Parameters[1].Type);
@@ -765,17 +772,19 @@ protected override ShapedQueryExpression TranslateLeftJoin(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateLongCount(ShapedQueryExpression source, LambdaExpression predicate)
+ protected override ShapedQueryExpression? TranslateLongCount(ShapedQueryExpression source, LambdaExpression? predicate)
{
Check.NotNull(source, nameof(source));
if (predicate != null)
{
- source = TranslateWhere(source, predicate);
- if (source == null)
+ var newSource = TranslateWhere(source, predicate);
+ if (newSource == null)
{
return null;
}
+
+ source = newSource;
}
var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression;
@@ -801,9 +810,9 @@ protected override ShapedQueryExpression TranslateLongCount(ShapedQueryExpressio
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateMax(
+ protected override ShapedQueryExpression? TranslateMax(
ShapedQueryExpression source,
- LambdaExpression selector,
+ LambdaExpression? selector,
Type resultType)
{
Check.NotNull(source, nameof(source));
@@ -817,7 +826,7 @@ protected override ShapedQueryExpression TranslateMax(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateMin(ShapedQueryExpression source, LambdaExpression selector, Type resultType)
+ protected override ShapedQueryExpression? TranslateMin(ShapedQueryExpression source, LambdaExpression? selector, Type resultType)
{
Check.NotNull(source, nameof(source));
@@ -830,7 +839,7 @@ protected override ShapedQueryExpression TranslateMin(ShapedQueryExpression sour
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression source, Type resultType)
+ protected override ShapedQueryExpression? TranslateOfType(ShapedQueryExpression source, Type resultType)
{
Check.NotNull(source, nameof(source));
Check.NotNull(resultType, nameof(resultType));
@@ -845,12 +854,13 @@ protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression s
var parameterExpression = Expression.Parameter(entityShaperExpression.Type);
var predicate = Expression.Lambda(Expression.TypeIs(parameterExpression, resultType), parameterExpression);
- source = TranslateWhere(source, predicate);
- if (source == null)
+ var newSource = TranslateWhere(source, predicate);
+ if (newSource == null)
{
// EntityType is not part of hierarchy
return null;
}
+ source = newSource;
var baseType = entityType.GetAllBaseTypes().SingleOrDefault(et => et.ClrType == resultType);
if (baseType != null)
@@ -884,7 +894,7 @@ protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression s
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateOrderBy(
+ protected override ShapedQueryExpression? TranslateOrderBy(
ShapedQueryExpression source,
LambdaExpression keySelector,
bool ascending)
@@ -894,11 +904,12 @@ protected override ShapedQueryExpression TranslateOrderBy(
var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression;
- keySelector = TranslateLambdaExpression(source, keySelector);
- if (keySelector == null)
+ var newKeySelector = TranslateLambdaExpression(source, keySelector);
+ if (newKeySelector == null)
{
return null;
}
+ keySelector = newKeySelector;
var orderBy = ascending ? EnumerableMethods.OrderBy : EnumerableMethods.OrderByDescending;
inMemoryQueryExpression.UpdateServerQueryExpression(
@@ -916,7 +927,7 @@ protected override ShapedQueryExpression TranslateOrderBy(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateReverse(ShapedQueryExpression source)
+ protected override ShapedQueryExpression? TranslateReverse(ShapedQueryExpression source)
{
Check.NotNull(source, nameof(source));
@@ -967,7 +978,7 @@ protected override ShapedQueryExpression TranslateSelect(ShapedQueryExpression s
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateSelectMany(
+ protected override ShapedQueryExpression? TranslateSelectMany(
ShapedQueryExpression source,
LambdaExpression collectionSelector,
LambdaExpression resultSelector)
@@ -1037,7 +1048,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpression source, LambdaExpression selector)
+ protected override ShapedQueryExpression? TranslateSelectMany(ShapedQueryExpression source, LambdaExpression selector)
{
Check.NotNull(source, nameof(source));
Check.NotNull(selector, nameof(selector));
@@ -1055,9 +1066,9 @@ protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpressi
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateSingleOrDefault(
+ protected override ShapedQueryExpression? TranslateSingleOrDefault(
ShapedQueryExpression source,
- LambdaExpression predicate,
+ LambdaExpression? predicate,
Type returnType,
bool returnDefault)
{
@@ -1079,17 +1090,18 @@ protected override ShapedQueryExpression TranslateSingleOrDefault(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateSkip(ShapedQueryExpression source, Expression count)
+ protected override ShapedQueryExpression? TranslateSkip(ShapedQueryExpression source, Expression count)
{
Check.NotNull(source, nameof(source));
Check.NotNull(count, nameof(count));
var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression;
- count = TranslateExpression(count);
- if (count == null)
+ var newCount = TranslateExpression(count);
+ if (newCount == null)
{
return null;
}
+ count = newCount;
inMemoryQueryExpression.UpdateServerQueryExpression(
Expression.Call(
@@ -1106,7 +1118,7 @@ protected override ShapedQueryExpression TranslateSkip(ShapedQueryExpression sou
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateSkipWhile(ShapedQueryExpression source, LambdaExpression predicate)
+ protected override ShapedQueryExpression? TranslateSkipWhile(ShapedQueryExpression source, LambdaExpression predicate)
{
Check.NotNull(source, nameof(source));
Check.NotNull(predicate, nameof(predicate));
@@ -1120,7 +1132,7 @@ protected override ShapedQueryExpression TranslateSkipWhile(ShapedQueryExpressio
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateSum(ShapedQueryExpression source, LambdaExpression selector, Type resultType)
+ protected override ShapedQueryExpression? TranslateSum(ShapedQueryExpression source, LambdaExpression? selector, Type resultType)
{
Check.NotNull(source, nameof(source));
Check.NotNull(resultType, nameof(resultType));
@@ -1134,17 +1146,18 @@ protected override ShapedQueryExpression TranslateSum(ShapedQueryExpression sour
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateTake(ShapedQueryExpression source, Expression count)
+ protected override ShapedQueryExpression? TranslateTake(ShapedQueryExpression source, Expression count)
{
Check.NotNull(source, nameof(source));
Check.NotNull(count, nameof(count));
var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression;
- count = TranslateExpression(count);
- if (count == null)
+ var newCount = TranslateExpression(count);
+ if (newCount == null)
{
return null;
}
+ count = newCount;
inMemoryQueryExpression.UpdateServerQueryExpression(
Expression.Call(
@@ -1161,7 +1174,7 @@ protected override ShapedQueryExpression TranslateTake(ShapedQueryExpression sou
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateTakeWhile(ShapedQueryExpression source, LambdaExpression predicate)
+ protected override ShapedQueryExpression? TranslateTakeWhile(ShapedQueryExpression source, LambdaExpression predicate)
{
Check.NotNull(source, nameof(source));
Check.NotNull(predicate, nameof(predicate));
@@ -1175,17 +1188,18 @@ protected override ShapedQueryExpression TranslateTakeWhile(ShapedQueryExpressio
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending)
+ protected override ShapedQueryExpression? TranslateThenBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending)
{
Check.NotNull(source, nameof(source));
Check.NotNull(keySelector, nameof(keySelector));
var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression;
- keySelector = TranslateLambdaExpression(source, keySelector);
- if (keySelector == null)
+ var newKeySelector = TranslateLambdaExpression(source, keySelector);
+ if (newKeySelector == null)
{
return null;
}
+ keySelector = newKeySelector;
inMemoryQueryExpression.UpdateServerQueryExpression(
Expression.Call(
@@ -1203,7 +1217,7 @@ protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression s
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateUnion(ShapedQueryExpression source1, ShapedQueryExpression source2)
+ protected override ShapedQueryExpression? TranslateUnion(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
Check.NotNull(source1, nameof(source1));
Check.NotNull(source2, nameof(source2));
@@ -1217,17 +1231,18 @@ protected override ShapedQueryExpression TranslateUnion(ShapedQueryExpression so
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override ShapedQueryExpression TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate)
+ protected override ShapedQueryExpression? TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate)
{
Check.NotNull(source, nameof(source));
Check.NotNull(predicate, nameof(predicate));
var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression;
- predicate = TranslateLambdaExpression(source, predicate, preserveType: true);
- if (predicate == null)
+ var newPredicate = TranslateLambdaExpression(source, predicate, preserveType: true);
+ if (newPredicate == null)
{
return null;
}
+ predicate = newPredicate;
inMemoryQueryExpression.UpdateServerQueryExpression(
Expression.Call(
@@ -1238,7 +1253,7 @@ protected override ShapedQueryExpression TranslateWhere(ShapedQueryExpression so
return source;
}
- private Expression TranslateExpression(Expression expression, bool preserveType = false)
+ private Expression? TranslateExpression(Expression expression, bool preserveType = false)
{
var translation = _expressionTranslator.Translate(expression);
if (translation == null && _expressionTranslator.TranslationErrorDetails != null)
@@ -1259,7 +1274,7 @@ private Expression TranslateExpression(Expression expression, bool preserveType
return translation;
}
- private LambdaExpression TranslateLambdaExpression(
+ private LambdaExpression? TranslateLambdaExpression(
ShapedQueryExpression shapedQueryExpression,
LambdaExpression lambdaExpression,
bool preserveType = false)
@@ -1286,15 +1301,16 @@ internal Expression ExpandWeakEntities(InMemoryQueryExpression queryExpression,
private sealed class WeakEntityExpandingExpressionVisitor : ExpressionVisitor
{
- private InMemoryQueryExpression _queryExpression;
private readonly InMemoryExpressionTranslatingExpressionVisitor _expressionTranslator;
+ private InMemoryQueryExpression _queryExpression;
public WeakEntityExpandingExpressionVisitor(InMemoryExpressionTranslatingExpressionVisitor expressionTranslator)
{
_expressionTranslator = expressionTranslator;
+ _queryExpression = null!;
}
- public string TranslationErrorDetails
+ public string? TranslationErrorDetails
=> _expressionTranslator.TranslationErrorDetails;
public Expression Expand(InMemoryQueryExpression queryExpression, Expression lambdaBody)
@@ -1347,7 +1363,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
: base.VisitExtension(extensionExpression);
}
- private Expression TryExpand(Expression source, MemberIdentity member)
+ private Expression? TryExpand(Expression source, MemberIdentity member)
{
source = source.UnwrapTypeConversion(out var convertedType);
if (!(source is EntityShaperExpression entityShaperExpression))
@@ -1426,11 +1442,20 @@ private Expression TryExpand(Expression source, MemberIdentity member)
return innerShapedQuery;
}
- var entityProjectionExpression
- = (EntityProjectionExpression)(entityShaperExpression.ValueBufferExpression is
- ProjectionBindingExpression projectionBindingExpression
- ? _queryExpression.GetMappedProjection(projectionBindingExpression.ProjectionMember)
- : entityShaperExpression.ValueBufferExpression);
+ EntityProjectionExpression entityProjectionExpression;
+ if (entityShaperExpression.ValueBufferExpression is ProjectionBindingExpression projectionBindingExpression)
+ {
+ if (projectionBindingExpression.ProjectionMember == null)
+ {
+ throw new InvalidOperationException();
+ }
+ entityProjectionExpression = (EntityProjectionExpression)_queryExpression.GetMappedProjection(
+ projectionBindingExpression.ProjectionMember);
+ }
+ else
+ {
+ entityProjectionExpression = (EntityProjectionExpression)entityShaperExpression.ValueBufferExpression;
+ }
var innerShaper = entityProjectionExpression.BindNavigation(navigation);
if (innerShaper == null)
@@ -1466,9 +1491,9 @@ ProjectionBindingExpression projectionBindingExpression
}
}
- private ShapedQueryExpression TranslateScalarAggregate(
+ private ShapedQueryExpression? TranslateScalarAggregate(
ShapedQueryExpression source,
- LambdaExpression selector,
+ LambdaExpression? selector,
string methodName,
Type returnType)
{
@@ -1507,9 +1532,9 @@ MethodInfo GetMethod()
};
}
- private ShapedQueryExpression TranslateSingleResultOperator(
+ private ShapedQueryExpression? TranslateSingleResultOperator(
ShapedQueryExpression source,
- LambdaExpression predicate,
+ LambdaExpression? predicate,
Type returnType,
MethodInfo method)
{
@@ -1517,11 +1542,12 @@ private ShapedQueryExpression TranslateSingleResultOperator(
if (predicate != null)
{
- source = TranslateWhere(source, predicate);
- if (source == null)
+ var newSource = TranslateWhere(source, predicate);
+ if (newSource == null)
{
return null;
}
+ source = newSource;
}
inMemoryQueryExpression.UpdateServerQueryExpression(
diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs
index 1bab63556f8..06206af6b05 100644
--- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs
+++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs
@@ -11,6 +11,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal
{
public partial class InMemoryShapedQueryCompilingExpressionVisitor
@@ -145,7 +147,7 @@ private static TResult MaterializeSingleResult(
ValueBuffer valueBuffer,
Func innerShaper)
=> valueBuffer.IsEmpty
- ? default
+ ? default!
: innerShaper(queryContext, valueBuffer);
protected override Expression VisitExtension(Expression extensionExpression)
@@ -155,9 +157,9 @@ protected override Expression VisitExtension(Expression extensionExpression)
if (extensionExpression is IncludeExpression includeExpression)
{
var entityClrType = includeExpression.EntityExpression.Type;
- var includingClrType = includeExpression.Navigation.DeclaringEntityType.ClrType;
+ var includingClrType = includeExpression.Navigation.DeclaringEntityType.ClrType!;
var inverseNavigation = includeExpression.Navigation.Inverse;
- var relatedEntityClrType = includeExpression.Navigation.TargetEntityType.ClrType;
+ var relatedEntityClrType = includeExpression.Navigation.TargetEntityType.ClrType!;
if (includingClrType != entityClrType
&& includingClrType.IsAssignableFrom(entityClrType))
{
diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.InMemoryProjectionBindingRemovingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.InMemoryProjectionBindingRemovingExpressionVisitor.cs
index 75440650364..4aa12a7672d 100644
--- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.InMemoryProjectionBindingRemovingExpressionVisitor.cs
+++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.InMemoryProjectionBindingRemovingExpressionVisitor.cs
@@ -12,6 +12,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using ExpressionExtensions = Microsoft.EntityFrameworkCore.Infrastructure.ExpressionExtensions;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal
{
public partial class InMemoryShapedQueryCompilingExpressionVisitor
@@ -65,7 +67,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
if (methodCallExpression.Method.IsGenericMethod
&& methodCallExpression.Method.GetGenericMethodDefinition() == ExpressionExtensions.ValueBufferTryReadValueMethod)
{
- var property = (IProperty)((ConstantExpression)methodCallExpression.Arguments[2]).Value;
+ var property = (IProperty?)((ConstantExpression)methodCallExpression.Arguments[2]).Value;
var (indexMap, valueBuffer) =
_materializationContextBindings[
(ParameterExpression)((MethodCallExpression)methodCallExpression.Arguments[0]).Object];
@@ -76,7 +78,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
return Expression.Call(
methodCallExpression.Method,
valueBuffer,
- Expression.Constant(indexMap[property]),
+ Expression.Constant(indexMap[property!]),
methodCallExpression.Arguments[2]);
}
@@ -105,7 +107,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
return base.VisitExtension(extensionExpression);
}
- private IPropertyBase InferPropertyFromInner(Expression expression)
+ private IPropertyBase? InferPropertyFromInner(Expression expression)
{
if (expression is MethodCallExpression methodCallExpression
&& methodCallExpression.Method.IsGenericMethod
@@ -125,7 +127,7 @@ private object GetProjectionIndex(
? ((ConstantExpression)queryExpression.GetMappedProjection(projectionBindingExpression.ProjectionMember)).Value
: (projectionBindingExpression.Index != null
? (object)projectionBindingExpression.Index
- : projectionBindingExpression.IndexMap);
+ : projectionBindingExpression.IndexMap!);
}
}
}
diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs
index 216ac490a36..5521bf2985b 100644
--- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs
+++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs
@@ -13,6 +13,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal
{
///
@@ -61,7 +63,6 @@ public string ToQueryString()
private sealed class Enumerator : IEnumerator, IAsyncEnumerator
{
- private IEnumerator _enumerator;
private readonly QueryContext _queryContext;
private readonly IEnumerable _innerEnumerable;
private readonly Func _shaper;
@@ -70,6 +71,8 @@ private sealed class Enumerator : IEnumerator, IAsyncEnumerator
private readonly bool _standAloneStateManager;
private readonly CancellationToken _cancellationToken;
+ private IEnumerator? _enumerator;
+
public Enumerator(QueryingEnumerable queryingEnumerable, CancellationToken cancellationToken = default)
{
_queryContext = queryingEnumerable._queryContext;
@@ -79,12 +82,13 @@ public Enumerator(QueryingEnumerable queryingEnumerable, CancellationToken ca
_queryLogger = queryingEnumerable._queryLogger;
_standAloneStateManager = queryingEnumerable._standAloneStateManager;
_cancellationToken = cancellationToken;
+ Current = default!;
}
public T Current { get; private set; }
object IEnumerator.Current
- => Current;
+ => Current!;
public bool MoveNext()
{
@@ -136,7 +140,7 @@ private bool MoveNextHelper()
Current = hasNext
? _shaper(_queryContext, _enumerator.Current)
- : default;
+ : default!;
return hasNext;
}
diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs
index c55301e6ea5..bf27e11648d 100644
--- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs
+++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs
@@ -11,6 +11,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal
{
public partial class InMemoryShapedQueryCompilingExpressionVisitor : ShapedQueryCompilingExpressionVisitor
diff --git a/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs
index 446ea91d876..435273fec98 100644
--- a/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs
+++ b/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal
{
///
@@ -17,7 +19,7 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal
///
public class ShaperExpressionProcessingExpressionVisitor : ExpressionVisitor
{
- private readonly InMemoryQueryExpression _queryExpression;
+ private readonly InMemoryQueryExpression? _queryExpression;
private readonly ParameterExpression _valueBufferParameter;
private readonly IDictionary _mapping = new Dictionary();
@@ -31,7 +33,7 @@ public class ShaperExpressionProcessingExpressionVisitor : ExpressionVisitor
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
public ShaperExpressionProcessingExpressionVisitor(
- [CanBeNull] InMemoryQueryExpression queryExpression,
+ [CanBeNull] InMemoryQueryExpression? queryExpression,
[NotNull] ParameterExpression valueBufferParameter)
{
_queryExpression = queryExpression;
diff --git a/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs b/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs
index 852149dcf4a..019bb3f0bb4 100644
--- a/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs
+++ b/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs
@@ -164,7 +164,7 @@ private static FromSqlQueryRootExpression GenerateFromSqlQueryRoot(
}
return new FromSqlQueryRootExpression(
- queryRootExpression.QueryProvider,
+ queryRootExpression.QueryProvider!,
entityType,
sql,
Expression.Constant(arguments));
diff --git a/src/EFCore.Relational/Query/EntityProjectionExpression.cs b/src/EFCore.Relational/Query/EntityProjectionExpression.cs
index 827ffff1a59..d61e44280c6 100644
--- a/src/EFCore.Relational/Query/EntityProjectionExpression.cs
+++ b/src/EFCore.Relational/Query/EntityProjectionExpression.cs
@@ -12,6 +12,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
@@ -51,7 +53,7 @@ public EntityProjectionExpression([NotNull] IEntityType entityType, [NotNull] Ta
public EntityProjectionExpression(
[NotNull] IEntityType entityType,
[NotNull] IDictionary propertyExpressionMap,
- [CanBeNull] SqlExpression discriminatorExpression = null)
+ [CanBeNull] SqlExpression? discriminatorExpression = null)
{
Check.NotNull(entityType, nameof(entityType));
Check.NotNull(propertyExpressionMap, nameof(propertyExpressionMap));
@@ -69,7 +71,7 @@ public EntityProjectionExpression(
///
/// A to generate discriminator for entity type.
///
- public virtual SqlExpression DiscriminatorExpression { get; }
+ public virtual SqlExpression? DiscriminatorExpression { get; }
///
public sealed override ExpressionType NodeType
@@ -77,7 +79,7 @@ public sealed override ExpressionType NodeType
///
public override Type Type
- => EntityType.ClrType;
+ => EntityType.ClrType!;
///
protected override Expression VisitChildren(ExpressionVisitor visitor)
@@ -204,7 +206,7 @@ public virtual void AddNavigationBinding([NotNull] INavigation navigation, [NotN
///
/// A navigation to bind.
/// An entity shaper expression for the target entity type of the navigation.
- public virtual EntityShaperExpression BindNavigation([NotNull] INavigation navigation)
+ public virtual EntityShaperExpression? BindNavigation([NotNull] INavigation navigation)
{
Check.NotNull(navigation, nameof(navigation));
diff --git a/src/EFCore.Relational/Query/ExpressionExtensions.cs b/src/EFCore.Relational/Query/ExpressionExtensions.cs
index 7de532f65d1..c724a2dee23 100644
--- a/src/EFCore.Relational/Query/ExpressionExtensions.cs
+++ b/src/EFCore.Relational/Query/ExpressionExtensions.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
@@ -25,7 +27,7 @@ public static class ExpressionExtensions
///
/// Expressions to search for to find the type mapping.
/// A relational type mapping inferred from the expressions.
- public static RelationalTypeMapping InferTypeMapping([NotNull] params SqlExpression[] expressions)
+ public static RelationalTypeMapping? InferTypeMapping([NotNull] params SqlExpression[] expressions)
{
Check.NotNull(expressions, nameof(expressions));
diff --git a/src/EFCore.Relational/Query/IMemberTranslator.cs b/src/EFCore.Relational/Query/IMemberTranslator.cs
index 8f8d93f660a..e3ab3bd2f27 100644
--- a/src/EFCore.Relational/Query/IMemberTranslator.cs
+++ b/src/EFCore.Relational/Query/IMemberTranslator.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
@@ -29,8 +31,8 @@ public interface IMemberTranslator
/// The return type from .
/// The query logger to use.
/// A SQL translation of the .
- SqlExpression Translate(
- [CanBeNull] SqlExpression instance,
+ SqlExpression? Translate(
+ [CanBeNull] SqlExpression? instance,
[NotNull] MemberInfo member,
[NotNull] Type returnType,
[NotNull] IDiagnosticsLogger logger);
diff --git a/src/EFCore.Relational/Query/IMemberTranslatorPlugin.cs b/src/EFCore.Relational/Query/IMemberTranslatorPlugin.cs
index 7929bd72612..e8dc043a953 100644
--- a/src/EFCore.Relational/Query/IMemberTranslatorPlugin.cs
+++ b/src/EFCore.Relational/Query/IMemberTranslatorPlugin.cs
@@ -4,6 +4,8 @@
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/IMemberTranslatorProvider.cs b/src/EFCore.Relational/Query/IMemberTranslatorProvider.cs
index e7472f9c75e..c0a975dcd2f 100644
--- a/src/EFCore.Relational/Query/IMemberTranslatorProvider.cs
+++ b/src/EFCore.Relational/Query/IMemberTranslatorProvider.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
@@ -31,8 +33,8 @@ public interface IMemberTranslatorProvider
/// The return type from .
/// The query logger to use.
/// A SQL translation of the .
- SqlExpression Translate(
- [CanBeNull] SqlExpression instance,
+ SqlExpression? Translate(
+ [CanBeNull] SqlExpression? instance,
[NotNull] MemberInfo member,
[NotNull] Type returnType,
[NotNull] IDiagnosticsLogger logger);
diff --git a/src/EFCore.Relational/Query/IMethodCallTranslator.cs b/src/EFCore.Relational/Query/IMethodCallTranslator.cs
index 0397812c0fc..200dd7be342 100644
--- a/src/EFCore.Relational/Query/IMethodCallTranslator.cs
+++ b/src/EFCore.Relational/Query/IMethodCallTranslator.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
@@ -29,8 +31,8 @@ public interface IMethodCallTranslator
/// SQL representations of .
/// The query logger to use.
/// A SQL translation of the .
- SqlExpression Translate(
- [CanBeNull] SqlExpression instance,
+ SqlExpression? Translate(
+ [CanBeNull] SqlExpression? instance,
[NotNull] MethodInfo method,
[NotNull] IReadOnlyList arguments,
[NotNull] IDiagnosticsLogger logger);
diff --git a/src/EFCore.Relational/Query/IMethodCallTranslatorPlugin.cs b/src/EFCore.Relational/Query/IMethodCallTranslatorPlugin.cs
index 456373b8714..fe7e6162678 100644
--- a/src/EFCore.Relational/Query/IMethodCallTranslatorPlugin.cs
+++ b/src/EFCore.Relational/Query/IMethodCallTranslatorPlugin.cs
@@ -4,6 +4,8 @@
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/IMethodCallTranslatorProvider.cs b/src/EFCore.Relational/Query/IMethodCallTranslatorProvider.cs
index ae1c8f1e503..9a6e13eb4ae 100644
--- a/src/EFCore.Relational/Query/IMethodCallTranslatorProvider.cs
+++ b/src/EFCore.Relational/Query/IMethodCallTranslatorProvider.cs
@@ -10,6 +10,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
@@ -33,9 +35,9 @@ public interface IMethodCallTranslatorProvider
/// SQL representations of .
/// The query logger to use.
/// A SQL translation of the .
- SqlExpression Translate(
+ SqlExpression? Translate(
[NotNull] IModel model,
- [CanBeNull] SqlExpression instance,
+ [CanBeNull] SqlExpression? instance,
[NotNull] MethodInfo method,
[NotNull] IReadOnlyList arguments,
[NotNull] IDiagnosticsLogger logger);
diff --git a/src/EFCore.Relational/Query/IQuerySqlGeneratorFactory.cs b/src/EFCore.Relational/Query/IQuerySqlGeneratorFactory.cs
index 2f440247de3..6905131498b 100644
--- a/src/EFCore.Relational/Query/IQuerySqlGeneratorFactory.cs
+++ b/src/EFCore.Relational/Query/IQuerySqlGeneratorFactory.cs
@@ -3,6 +3,8 @@
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/IRelationalParameterBasedSqlProcessorFactory.cs b/src/EFCore.Relational/Query/IRelationalParameterBasedSqlProcessorFactory.cs
index 668ca42505f..5f39b4943e7 100644
--- a/src/EFCore.Relational/Query/IRelationalParameterBasedSqlProcessorFactory.cs
+++ b/src/EFCore.Relational/Query/IRelationalParameterBasedSqlProcessorFactory.cs
@@ -3,6 +3,8 @@
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/IRelationalQueryStringFactory.cs b/src/EFCore.Relational/Query/IRelationalQueryStringFactory.cs
index 7145a58aa37..e997de7e4e4 100644
--- a/src/EFCore.Relational/Query/IRelationalQueryStringFactory.cs
+++ b/src/EFCore.Relational/Query/IRelationalQueryStringFactory.cs
@@ -4,6 +4,8 @@
using System.Data.Common;
using JetBrains.Annotations;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/IRelationalSqlTranslatingExpressionVisitorFactory.cs b/src/EFCore.Relational/Query/IRelationalSqlTranslatingExpressionVisitorFactory.cs
index 78911f96a93..9a3e6b04c1d 100644
--- a/src/EFCore.Relational/Query/IRelationalSqlTranslatingExpressionVisitorFactory.cs
+++ b/src/EFCore.Relational/Query/IRelationalSqlTranslatingExpressionVisitorFactory.cs
@@ -4,6 +4,8 @@
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/ISqlExpressionFactory.cs b/src/EFCore.Relational/Query/ISqlExpressionFactory.cs
index d233cc655d7..f5e6b167b9e 100644
--- a/src/EFCore.Relational/Query/ISqlExpressionFactory.cs
+++ b/src/EFCore.Relational/Query/ISqlExpressionFactory.cs
@@ -9,6 +9,9 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;
+using CA = System.Diagnostics.CodeAnalysis;
+
+#nullable enable
namespace Microsoft.EntityFrameworkCore.Query
{
@@ -30,7 +33,7 @@ public interface ISqlExpressionFactory
/// The object to get the mapping for.
/// The type mapping to be used.
[Obsolete("Use IRelationalTypeMappingSource directly.")]
- RelationalTypeMapping GetTypeMappingForValue([CanBeNull] object value);
+ RelationalTypeMapping GetTypeMappingForValue([CanBeNull] object? value);
///
/// Finds the type mapping for a given .
@@ -46,14 +49,16 @@ public interface ISqlExpressionFactory
/// A SQL expression to apply type mapping.
/// A type mapping to apply.
/// A SQL expression with given type mapping applied.
- SqlExpression ApplyTypeMapping([CanBeNull] SqlExpression sqlExpression, [CanBeNull] RelationalTypeMapping typeMapping);
+ [return: CA.NotNullIfNotNull("sqlExpression")]
+ SqlExpression? ApplyTypeMapping([CanBeNull] SqlExpression? sqlExpression, [CanBeNull] RelationalTypeMapping? typeMapping);
///
/// Applies default type mapping to given .
///
/// A SQL Expression to apply default type mapping.
/// A SQL expression with default type mapping applied.
- SqlExpression ApplyDefaultTypeMapping([CanBeNull] SqlExpression sqlExpression);
+ [return: CA.NotNullIfNotNull("sqlExpression")]
+ SqlExpression? ApplyDefaultTypeMapping([CanBeNull] SqlExpression? sqlExpression);
///
/// Creates a new with the given arguments.
@@ -63,11 +68,11 @@ public interface ISqlExpressionFactory
/// The type of the created expression.
/// A type mapping to be assigned to the created expression.
/// A with the given arguments.
- SqlUnaryExpression MakeUnary(
+ SqlUnaryExpression? MakeUnary(
ExpressionType operatorType,
[NotNull] SqlExpression operand,
[NotNull] Type type,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new with the given arguments.
@@ -77,11 +82,11 @@ SqlUnaryExpression MakeUnary(
/// The right operand of binary operation.
/// A type mapping to be assigned to the created expression.
/// A with the given arguments.
- SqlBinaryExpression MakeBinary(
+ SqlBinaryExpression? MakeBinary(
ExpressionType operatorType,
[NotNull] SqlExpression left,
[NotNull] SqlExpression right,
- [CanBeNull] RelationalTypeMapping typeMapping);
+ [CanBeNull] RelationalTypeMapping? typeMapping);
// Comparison
///
@@ -160,7 +165,7 @@ SqlBinaryExpression MakeBinary(
SqlBinaryExpression Add(
[NotNull] SqlExpression left,
[NotNull] SqlExpression right,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a which represents a subtraction.
@@ -172,7 +177,7 @@ SqlBinaryExpression Add(
SqlBinaryExpression Subtract(
[NotNull] SqlExpression left,
[NotNull] SqlExpression right,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a which represents a multiplication.
@@ -184,7 +189,7 @@ SqlBinaryExpression Subtract(
SqlBinaryExpression Multiply(
[NotNull] SqlExpression left,
[NotNull] SqlExpression right,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a which represents a division.
@@ -196,7 +201,7 @@ SqlBinaryExpression Multiply(
SqlBinaryExpression Divide(
[NotNull] SqlExpression left,
[NotNull] SqlExpression right,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a which represents a modulo operation.
@@ -208,7 +213,7 @@ SqlBinaryExpression Divide(
SqlBinaryExpression Modulo(
[NotNull] SqlExpression left,
[NotNull] SqlExpression right,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
// Bitwise
///
@@ -221,7 +226,7 @@ SqlBinaryExpression Modulo(
SqlBinaryExpression And(
[NotNull] SqlExpression left,
[NotNull] SqlExpression right,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a which represents a bitwise OR operation.
@@ -233,7 +238,7 @@ SqlBinaryExpression And(
SqlBinaryExpression Or(
[NotNull] SqlExpression left,
[NotNull] SqlExpression right,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
// Other
///
@@ -246,7 +251,7 @@ SqlBinaryExpression Or(
SqlFunctionExpression Coalesce(
[NotNull] SqlExpression left,
[NotNull] SqlExpression right,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represent equality to null.
@@ -272,7 +277,7 @@ SqlFunctionExpression Coalesce(
SqlUnaryExpression Convert(
[NotNull] SqlExpression operand,
[NotNull] Type type,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represent a NOT operation in a SQL tree.
@@ -307,7 +312,7 @@ SqlUnaryExpression Convert(
CaseExpression Case(
[NotNull] SqlExpression operand,
[NotNull] IReadOnlyList whenClauses,
- [CanBeNull] SqlExpression elseResult);
+ [CanBeNull] SqlExpression? elseResult);
///
/// Creates a new which represent a CASE statement in a SQL tree.
@@ -315,7 +320,7 @@ CaseExpression Case(
/// A list of to evaluate condition and get result from.
/// A value to return if no matches, if any.
/// An expression representing a CASE statement in a SQL tree.
- CaseExpression Case([NotNull] IReadOnlyList whenClauses, [CanBeNull] SqlExpression elseResult);
+ CaseExpression Case([NotNull] IReadOnlyList whenClauses, [CanBeNull] SqlExpression? elseResult);
///
/// Creates a new which represents a function call in a SQL tree.
@@ -330,7 +335,7 @@ SqlFunctionExpression Function(
[NotNull] string name,
[NotNull] IEnumerable arguments,
[NotNull] Type returnType,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represents a function call in a SQL tree.
@@ -343,11 +348,11 @@ SqlFunctionExpression Function(
/// An expression representing a function call in a SQL tree.
[Obsolete("Use overload that explicitly specifies value for 'argumentsPropagateNullability' argument.")]
SqlFunctionExpression Function(
- [CanBeNull] string schema,
+ [CanBeNull] string? schema,
[NotNull] string name,
[NotNull] IEnumerable arguments,
[NotNull] Type returnType,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represents a function call in a SQL tree.
@@ -365,7 +370,7 @@ SqlFunctionExpression Function(
[NotNull] string name,
[NotNull] IEnumerable arguments,
[NotNull] Type returnType,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represents a function call in a SQL tree.
@@ -378,7 +383,7 @@ SqlFunctionExpression Function(
SqlFunctionExpression Function(
[NotNull] string name,
[NotNull] Type returnType,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represents a function call in a SQL tree.
@@ -393,7 +398,7 @@ SqlFunctionExpression Function(
[NotNull] string schema,
[NotNull] string name,
[NotNull] Type returnType,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represents a function call in a SQL tree.
@@ -408,7 +413,7 @@ SqlFunctionExpression Function(
[NotNull] SqlExpression instance,
[NotNull] string name,
[NotNull] Type returnType,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represents a function call in a SQL tree.
@@ -426,7 +431,7 @@ SqlFunctionExpression Function(
bool nullable,
[NotNull] IEnumerable argumentsPropagateNullability,
[NotNull] Type returnType,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represents a function call in a SQL tree.
@@ -446,7 +451,7 @@ SqlFunctionExpression Function(
bool nullable,
[NotNull] IEnumerable argumentsPropagateNullability,
[NotNull] Type returnType,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represents a function call in a SQL tree.
@@ -468,7 +473,7 @@ SqlFunctionExpression Function(
bool instancePropagatesNullability,
[NotNull] IEnumerable argumentsPropagateNullability,
[NotNull] Type returnType,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represents a niladic function call in a SQL tree.
@@ -482,7 +487,7 @@ SqlFunctionExpression NiladicFunction(
[NotNull] string name,
bool nullable,
[NotNull] Type returnType,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represents a niladic function call in a SQL tree.
@@ -498,7 +503,7 @@ SqlFunctionExpression NiladicFunction(
[NotNull] string name,
bool nullable,
[NotNull] Type returnType,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represents a niladic function call in a SQL tree.
@@ -516,7 +521,7 @@ SqlFunctionExpression NiladicFunction(
bool nullable,
bool instancePropagatesNullability,
[NotNull] Type returnType,
- [CanBeNull] RelationalTypeMapping typeMapping = null);
+ [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represents an EXISTS operation in a SQL tree.
@@ -551,7 +556,7 @@ SqlFunctionExpression NiladicFunction(
/// A pattern to search.
/// An optional escape character to use in LIKE.
/// An expression representing a LIKE in a SQL tree.
- LikeExpression Like([NotNull] SqlExpression match, [NotNull] SqlExpression pattern, [CanBeNull] SqlExpression escapeChar = null);
+ LikeExpression Like([NotNull] SqlExpression match, [NotNull] SqlExpression pattern, [CanBeNull] SqlExpression? escapeChar = null);
///
/// Creates a new which represents a constant in a SQL tree.
@@ -559,7 +564,7 @@ SqlFunctionExpression NiladicFunction(
/// A value.
/// The associated with the expression.
/// An expression representing a LIKE in a SQL tree.
- SqlConstantExpression Constant([NotNull] object value, [CanBeNull] RelationalTypeMapping typeMapping = null);
+ SqlConstantExpression Constant([CanBeNull] object? value, [CanBeNull] RelationalTypeMapping? typeMapping = null);
///
/// Creates a new which represents a SQL token.
@@ -574,7 +579,7 @@ SqlFunctionExpression NiladicFunction(
///
/// A to project.
/// An expression representing a SELECT in a SQL tree.
- SelectExpression Select([CanBeNull] SqlExpression projection);
+ SelectExpression Select([CanBeNull] SqlExpression? projection);
///
/// Creates a new which represents a SELECT in a SQL tree projecting an entity type from
diff --git a/src/EFCore.Relational/Query/Internal/BufferedDataReader.cs b/src/EFCore.Relational/Query/Internal/BufferedDataReader.cs
index 690e3ee34a8..4dbc054c7ba 100644
--- a/src/EFCore.Relational/Query/Internal/BufferedDataReader.cs
+++ b/src/EFCore.Relational/Query/Internal/BufferedDataReader.cs
@@ -16,6 +16,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -26,8 +28,9 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal
///
public class BufferedDataReader : DbDataReader
{
- private DbDataReader _underlyingReader;
private readonly bool _detailedErrorsEnabled;
+
+ private DbDataReader? _underlyingReader;
private List _bufferedDataRecords = new List();
private BufferedDataRecord _currentResultSet;
private int _currentResultSetNumber;
@@ -45,6 +48,7 @@ public BufferedDataReader([NotNull] DbDataReader reader, bool detailedErrorsEnab
{
_underlyingReader = reader;
_detailedErrorsEnabled = detailedErrorsEnabled;
+ _currentResultSet = null!;
}
///
@@ -261,7 +265,7 @@ public static bool IsSupportedValueType([NotNull] Type type)
///
public override void Close()
{
- _bufferedDataRecords = null;
+ _bufferedDataRecords = null!;
_isClosed = true;
var reader = _underlyingReader;
@@ -612,7 +616,7 @@ public override bool NextResult()
return true;
}
- _currentResultSet = null;
+ _currentResultSet = null!;
return false;
}
@@ -713,6 +717,38 @@ private sealed class BufferedDataRecord
public BufferedDataRecord(bool detailedErrorsEnabled)
{
_detailedErrorsEnabled = detailedErrorsEnabled;
+ _dataTypeNames = null!;
+ _columnNames = null!;
+ _columns = null!;
+ _columnTypeCases = null!;
+ _fieldNameLookup = null!;
+ _fieldTypes = null!;
+ _indexMap = null!;
+ _nullOrdinalToIndexMap = null!;
+ _ordinalToIndexMap = null!;
+ _underlyingReader = null!;
+
+ _bools = null!;
+ _bytes = null!;
+ _chars = null!;
+ _dateTimeOffsets = null!;
+ _dateTimes = null!;
+ _decimals = null!;
+ _doubles = null!;
+ _floats = null!;
+ _guids = null!;
+ _ints = null!;
+ _longs = null!;
+ _longs = null!;
+ _nulls = null!;
+ _objects = null!;
+ _sbytes = null!;
+ _shorts = null!;
+ _tempBools = null!;
+ _tempNulls = null!;
+ _uints = null!;
+ _ulongs = null!;
+ _ushorts = null!;
}
public bool IsDataReady { get; private set; }
@@ -876,13 +912,13 @@ public BufferedDataRecord Initialize([NotNull] DbDataReader reader, [NotNull] IR
}
_bools = new BitArray(_tempBools);
- _tempBools = null;
+ _tempBools = null!;
_nulls = new BitArray(_tempNulls);
- _tempNulls = null;
+ _tempNulls = null!;
_rowCount = _currentRowNumber + 1;
_currentRowNumber = -1;
- _underlyingReader = null;
- _columns = null;
+ _underlyingReader = null!;
+ _columns = null!;
return this;
}
@@ -904,13 +940,13 @@ public async Task InitializeAsync(
}
_bools = new BitArray(_tempBools);
- _tempBools = null;
+ _tempBools = null!;
_nulls = new BitArray(_tempNulls);
- _tempNulls = null;
+ _tempNulls = null!;
_rowCount = _currentRowNumber + 1;
_currentRowNumber = -1;
- _underlyingReader = null;
- _columns = null;
+ _underlyingReader = null!;
+ _columns = null!;
return this;
}
diff --git a/src/EFCore.Relational/Query/Internal/ByteArraySequenceEqualTranslator.cs b/src/EFCore.Relational/Query/Internal/ByteArraySequenceEqualTranslator.cs
index 9d354385890..2183749167f 100644
--- a/src/EFCore.Relational/Query/Internal/ByteArraySequenceEqualTranslator.cs
+++ b/src/EFCore.Relational/Query/Internal/ByteArraySequenceEqualTranslator.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -37,8 +39,8 @@ public ByteArraySequenceEqualTranslator([NotNull] ISqlExpressionFactory sqlExpre
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual SqlExpression Translate(
- SqlExpression instance,
+ public virtual SqlExpression? Translate(
+ SqlExpression? instance,
MethodInfo method,
IReadOnlyList arguments,
IDiagnosticsLogger logger)
diff --git a/src/EFCore.Relational/Query/Internal/CollateTranslator.cs b/src/EFCore.Relational/Query/Internal/CollateTranslator.cs
index cb5b958d107..f43a3f6cb44 100644
--- a/src/EFCore.Relational/Query/Internal/CollateTranslator.cs
+++ b/src/EFCore.Relational/Query/Internal/CollateTranslator.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -26,8 +28,8 @@ private static readonly MethodInfo _methodInfo
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual SqlExpression Translate(
- SqlExpression instance,
+ public virtual SqlExpression? Translate(
+ SqlExpression? instance,
MethodInfo method,
IReadOnlyList arguments,
IDiagnosticsLogger logger)
diff --git a/src/EFCore.Relational/Query/Internal/CollectionJoinApplyingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/CollectionJoinApplyingExpressionVisitor.cs
index 2cce355400d..8d1ebb65676 100644
--- a/src/EFCore.Relational/Query/Internal/CollectionJoinApplyingExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/Internal/CollectionJoinApplyingExpressionVisitor.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -72,7 +74,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
var innerShaper = Visit(collectionShaperExpression.InnerShaper);
var collectionJoin = selectExpression.ApplyCollectionJoin(
- projectionBindingExpression.Index.Value,
+ projectionBindingExpression.Index!.Value,
collectionId,
innerShaper,
collectionShaperExpression.Navigation,
@@ -89,7 +91,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
nameof(RelationalQueryableExtensions.AsSingleQuery)));
}
- return collectionJoin;
+ return collectionJoin!;
}
return extensionExpression is ShapedQueryExpression shapedQueryExpression
diff --git a/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs b/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs
index ac06c0e49a2..933c9e6ca9d 100644
--- a/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs
+++ b/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -37,8 +39,8 @@ public ComparisonTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactory
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual SqlExpression Translate(
- SqlExpression instance,
+ public virtual SqlExpression? Translate(
+ SqlExpression? instance,
MethodInfo method,
IReadOnlyList arguments,
IDiagnosticsLogger logger)
@@ -49,8 +51,8 @@ public virtual SqlExpression Translate(
if (method.ReturnType == typeof(int))
{
- SqlExpression left = null;
- SqlExpression right = null;
+ SqlExpression? left = null;
+ SqlExpression? right = null;
if (method.Name == nameof(string.Compare)
&& arguments.Count == 2
&& arguments[0].Type == arguments[1].Type)
diff --git a/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs b/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs
index 66a6e6169d4..692cc1cfc1c 100644
--- a/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs
+++ b/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -38,8 +40,8 @@ public ContainsTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactory)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual SqlExpression Translate(
- SqlExpression instance,
+ public virtual SqlExpression? Translate(
+ SqlExpression? instance,
MethodInfo method,
IReadOnlyList arguments,
IDiagnosticsLogger logger)
@@ -57,6 +59,7 @@ public virtual SqlExpression Translate(
if (arguments.Count == 1
&& method.IsContainsMethod()
+ && instance != null
&& ValidateValues(instance))
{
return _sqlExpressionFactory.In(RemoveObjectConvert(arguments[0]), instance, negated: false);
diff --git a/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs b/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs
index af6c451b9ed..a382c5f3e56 100644
--- a/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs
+++ b/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -41,8 +43,8 @@ public EnumHasFlagTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactor
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual SqlExpression Translate(
- SqlExpression instance,
+ public virtual SqlExpression? Translate(
+ SqlExpression? instance,
MethodInfo method,
IReadOnlyList arguments,
IDiagnosticsLogger logger)
@@ -51,7 +53,8 @@ public virtual SqlExpression Translate(
Check.NotNull(arguments, nameof(arguments));
Check.NotNull(logger, nameof(logger));
- if (Equals(method, _methodInfo))
+ if (Equals(method, _methodInfo)
+ && instance != null)
{
var argument = arguments[0];
return instance.Type != argument.Type
diff --git a/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs b/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs
index 23cbfc6ce91..0451af9eff6 100644
--- a/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs
+++ b/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -37,8 +39,8 @@ public EqualsTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactory)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual SqlExpression Translate(
- SqlExpression instance,
+ public virtual SqlExpression? Translate(
+ SqlExpression? instance,
MethodInfo method,
IReadOnlyList arguments,
IDiagnosticsLogger logger)
@@ -47,8 +49,8 @@ public virtual SqlExpression Translate(
Check.NotNull(arguments, nameof(arguments));
Check.NotNull(logger, nameof(logger));
- SqlExpression left = null;
- SqlExpression right = null;
+ SqlExpression? left = null;
+ SqlExpression? right = null;
if (method.Name == nameof(object.Equals)
&& instance != null
diff --git a/src/EFCore.Relational/Query/Internal/FromSqlParameterExpandingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/FromSqlParameterExpandingExpressionVisitor.cs
index a0aafb5a51f..71bcc951e79 100644
--- a/src/EFCore.Relational/Query/Internal/FromSqlParameterExpandingExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/Internal/FromSqlParameterExpandingExpressionVisitor.cs
@@ -12,6 +12,8 @@
using Microsoft.EntityFrameworkCore.Storage.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -47,6 +49,8 @@ public FromSqlParameterExpandingExpressionVisitor(
_sqlExpressionFactory = dependencies.SqlExpressionFactory;
_typeMappingSource = dependencies.TypeMappingSource;
_parameterNameGeneratorFactory = dependencies.ParameterNameGeneratorFactory;
+ _parametersValues = default!;
+ _parameterNameGenerator = default!;
}
///
diff --git a/src/EFCore.Relational/Query/Internal/FromSqlQueryRootExpression.cs b/src/EFCore.Relational/Query/Internal/FromSqlQueryRootExpression.cs
index 6fb91b1586b..21915c536d5 100644
--- a/src/EFCore.Relational/Query/Internal/FromSqlQueryRootExpression.cs
+++ b/src/EFCore.Relational/Query/Internal/FromSqlQueryRootExpression.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -118,7 +120,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is FromSqlQueryRootExpression queryRootExpression
diff --git a/src/EFCore.Relational/Query/Internal/FromSqlQueryingEnumerable.cs b/src/EFCore.Relational/Query/Internal/FromSqlQueryingEnumerable.cs
index d52963c2028..8b0cf8b193d 100644
--- a/src/EFCore.Relational/Query/Internal/FromSqlQueryingEnumerable.cs
+++ b/src/EFCore.Relational/Query/Internal/FromSqlQueryingEnumerable.cs
@@ -13,6 +13,8 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -154,8 +156,8 @@ private sealed class Enumerator : IEnumerator
private readonly bool _standAloneStateManager;
private readonly bool _detailedErrorsEnabled;
- private RelationalDataReader _dataReader;
- private int[] _indexMap;
+ private RelationalDataReader? _dataReader;
+ private int[]? _indexMap;
public Enumerator(FromSqlQueryingEnumerable queryingEnumerable)
{
@@ -167,12 +169,13 @@ public Enumerator(FromSqlQueryingEnumerable queryingEnumerable)
_queryLogger = queryingEnumerable._queryLogger;
_standAloneStateManager = queryingEnumerable._standAloneStateManager;
_detailedErrorsEnabled = queryingEnumerable._detailedErrorsEnabled;
+ Current = default!;
}
public T Current { get; private set; }
object IEnumerator.Current
- => Current;
+ => Current!;
public bool MoveNext()
{
@@ -186,11 +189,11 @@ public bool MoveNext()
.Execute(true, InitializeReader, null);
}
- var hasNext = _dataReader.Read();
+ var hasNext = _dataReader!.Read();
Current = hasNext
- ? _shaper(_relationalQueryContext, _dataReader.DbDataReader, _indexMap)
- : default;
+ ? _shaper(_relationalQueryContext, _dataReader.DbDataReader, _indexMap!)
+ : default!;
return hasNext;
}
@@ -246,8 +249,8 @@ private sealed class AsyncEnumerator : IAsyncEnumerator
private readonly bool _standAloneStateManager;
private readonly bool _detailedErrorsEnabled;
- private RelationalDataReader _dataReader;
- private int[] _indexMap;
+ private RelationalDataReader? _dataReader;
+ private int[]? _indexMap;
public AsyncEnumerator(FromSqlQueryingEnumerable queryingEnumerable)
{
@@ -259,6 +262,7 @@ public AsyncEnumerator(FromSqlQueryingEnumerable queryingEnumerable)
_queryLogger = queryingEnumerable._queryLogger;
_standAloneStateManager = queryingEnumerable._standAloneStateManager;
_detailedErrorsEnabled = queryingEnumerable._detailedErrorsEnabled;
+ Current = default!;
}
public T Current { get; private set; }
@@ -275,11 +279,11 @@ await _relationalQueryContext.ExecutionStrategyFactory.Create()
.ExecuteAsync(true, InitializeReaderAsync, null, _relationalQueryContext.CancellationToken).ConfigureAwait(false);
}
- var hasNext = await _dataReader.ReadAsync(_relationalQueryContext.CancellationToken).ConfigureAwait(false);
+ var hasNext = await _dataReader!.ReadAsync(_relationalQueryContext.CancellationToken).ConfigureAwait(false);
Current = hasNext
- ? _shaper(_relationalQueryContext, _dataReader.DbDataReader, _indexMap)
- : default;
+ ? _shaper(_relationalQueryContext, _dataReader.DbDataReader, _indexMap!)
+ : default!;
return hasNext;
}
diff --git a/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs b/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs
index a89ca66c151..1a3cbd64671 100644
--- a/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs
+++ b/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -38,8 +40,8 @@ public GetValueOrDefaultTranslator([NotNull] ISqlExpressionFactory sqlExpression
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual SqlExpression Translate(
- SqlExpression instance,
+ public virtual SqlExpression? Translate(
+ SqlExpression? instance,
MethodInfo method,
IReadOnlyList arguments,
IDiagnosticsLogger logger)
@@ -49,6 +51,7 @@ public virtual SqlExpression Translate(
Check.NotNull(logger, nameof(logger));
if (method.Name == nameof(Nullable.GetValueOrDefault)
+ && instance != null
&& method.ReturnType.IsNumeric())
{
return _sqlExpressionFactory.Coalesce(
diff --git a/src/EFCore.Relational/Query/Internal/IRelationalQueryingEnumerable.cs b/src/EFCore.Relational/Query/Internal/IRelationalQueryingEnumerable.cs
index 294c631109c..855011a6566 100644
--- a/src/EFCore.Relational/Query/Internal/IRelationalQueryingEnumerable.cs
+++ b/src/EFCore.Relational/Query/Internal/IRelationalQueryingEnumerable.cs
@@ -3,6 +3,8 @@
using System.Data.Common;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
diff --git a/src/EFCore.Relational/Query/Internal/LikeTranslator.cs b/src/EFCore.Relational/Query/Internal/LikeTranslator.cs
index 9eae550a94d..b305e31480a 100644
--- a/src/EFCore.Relational/Query/Internal/LikeTranslator.cs
+++ b/src/EFCore.Relational/Query/Internal/LikeTranslator.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -47,8 +49,8 @@ public LikeTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactory)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual SqlExpression Translate(
- SqlExpression instance,
+ public virtual SqlExpression? Translate(
+ SqlExpression? instance,
MethodInfo method,
IReadOnlyList arguments,
IDiagnosticsLogger logger)
diff --git a/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs b/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs
index fbd4176fd09..aed293011ec 100644
--- a/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs
+++ b/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -37,8 +39,8 @@ public NullableMemberTranslator([NotNull] ISqlExpressionFactory sqlExpressionFac
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual SqlExpression Translate(
- SqlExpression instance,
+ public virtual SqlExpression? Translate(
+ SqlExpression? instance,
MemberInfo member,
Type returnType,
IDiagnosticsLogger logger)
@@ -47,7 +49,8 @@ public virtual SqlExpression Translate(
Check.NotNull(returnType, nameof(returnType));
Check.NotNull(logger, nameof(logger));
- if (member.DeclaringType.IsNullableValueType())
+ if (member.DeclaringType.IsNullableValueType()
+ && instance != null)
{
switch (member.Name)
{
diff --git a/src/EFCore.Relational/Query/Internal/QuerySqlGeneratorFactory.cs b/src/EFCore.Relational/Query/Internal/QuerySqlGeneratorFactory.cs
index 1e579627f79..6411cd37e0d 100644
--- a/src/EFCore.Relational/Query/Internal/QuerySqlGeneratorFactory.cs
+++ b/src/EFCore.Relational/Query/Internal/QuerySqlGeneratorFactory.cs
@@ -4,6 +4,8 @@
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
diff --git a/src/EFCore.Relational/Query/Internal/RelationalCommandCache.cs b/src/EFCore.Relational/Query/Internal/RelationalCommandCache.cs
index 0a8e9a23692..ae1fbb89cef 100644
--- a/src/EFCore.Relational/Query/Internal/RelationalCommandCache.cs
+++ b/src/EFCore.Relational/Query/Internal/RelationalCommandCache.cs
@@ -10,6 +10,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.Caching.Memory;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -39,7 +41,7 @@ public RelationalCommandCache(
[NotNull] IQuerySqlGeneratorFactory querySqlGeneratorFactory,
[NotNull] IRelationalParameterBasedSqlProcessorFactory relationalParameterBasedSqlProcessorFactory,
[NotNull] SelectExpression selectExpression,
- [NotNull] IReadOnlyList readerColumns,
+ [CanBeNull] IReadOnlyList? readerColumns,
bool useRelationalNulls)
{
_memoryCache = memoryCache;
@@ -55,7 +57,7 @@ public RelationalCommandCache(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual IReadOnlyList ReaderColumns { get; }
+ public virtual IReadOnlyList? ReaderColumns { get; }
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -129,7 +131,7 @@ public CommandCacheKey(SelectExpression selectExpression, IReadOnlyDictionary obj is CommandCacheKey commandCacheKey
&& Equals(commandCacheKey);
diff --git a/src/EFCore.Relational/Query/Internal/RelationalParameterBasedSqlProcessorFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalParameterBasedSqlProcessorFactory.cs
index e0568526184..adeff040d9a 100644
--- a/src/EFCore.Relational/Query/Internal/RelationalParameterBasedSqlProcessorFactory.cs
+++ b/src/EFCore.Relational/Query/Internal/RelationalParameterBasedSqlProcessorFactory.cs
@@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
diff --git a/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs
index e15ceee0707..416b1f9b130 100644
--- a/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs
@@ -14,6 +14,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -54,6 +56,8 @@ public RelationalProjectionBindingExpressionVisitor(
_queryableMethodTranslatingExpressionVisitor = queryableMethodTranslatingExpressionVisitor;
_sqlTranslator = sqlTranslatingExpressionVisitor;
_includeFindingExpressionVisitor = new IncludeFindingExpressionVisitor();
+ _selectExpression = null!;
+ _existingProjections = Array.Empty();
}
///
@@ -85,11 +89,11 @@ public virtual Expression Translate([NotNull] SelectExpression selectExpression,
}
_selectExpression.ReplaceProjectionMapping(_projectionMapping);
- _selectExpression = null;
+ _selectExpression = null!;
_projectionMembers.Clear();
_projectionMapping.Clear();
- result = MatchTypes(result, expression.Type);
+ result = MatchTypes(result!, expression.Type);
return result;
}
@@ -100,7 +104,7 @@ public virtual Expression Translate([NotNull] SelectExpression selectExpression,
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public override Expression Visit(Expression expression)
+ public override Expression? Visit(Expression? expression)
{
if (expression == null)
{
@@ -162,9 +166,9 @@ public override Expression Visit(Expression expression)
case MaterializeCollectionNavigationExpression materializeCollectionNavigationExpression:
return _selectExpression.AddCollectionProjection(
_queryableMethodTranslatingExpressionVisitor.TranslateSubquery(
- materializeCollectionNavigationExpression.Subquery),
+ materializeCollectionNavigationExpression.Subquery)!,
materializeCollectionNavigationExpression.Navigation,
- materializeCollectionNavigationExpression.Navigation.ClrType.TryGetSequenceType());
+ materializeCollectionNavigationExpression.Navigation.ClrType.TryGetSequenceType()!);
case MethodCallExpression methodCallExpression:
{
@@ -256,8 +260,8 @@ static bool IsAggregateResultWithCustomShaper(MethodInfo method)
///
protected override Expression VisitBinary(BinaryExpression binaryExpression)
{
- var left = MatchTypes(Visit(binaryExpression.Left), binaryExpression.Left.Type);
- var right = MatchTypes(Visit(binaryExpression.Right), binaryExpression.Right.Type);
+ var left = MatchTypes(Visit(binaryExpression.Left)!, binaryExpression.Left.Type);
+ var right = MatchTypes(Visit(binaryExpression.Right)!, binaryExpression.Right.Type);
return binaryExpression.Update(left, VisitAndConvert(binaryExpression.Conversion, "VisitBinary"), right);
}
@@ -270,9 +274,9 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
///
protected override Expression VisitConditional(ConditionalExpression conditionalExpression)
{
- var test = Visit(conditionalExpression.Test);
- var ifTrue = Visit(conditionalExpression.IfTrue);
- var ifFalse = Visit(conditionalExpression.IfFalse);
+ var test = Visit(conditionalExpression.Test)!;
+ var ifTrue = Visit(conditionalExpression.IfTrue)!;
+ var ifFalse = Visit(conditionalExpression.IfFalse)!;
if (test.Type == typeof(bool?))
{
@@ -288,7 +292,7 @@ protected override Expression VisitConditional(ConditionalExpression conditional
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitExtension(Expression extensionExpression)
+ protected override Expression? VisitExtension(Expression extensionExpression)
{
Check.NotNull(extensionExpression, nameof(extensionExpression));
@@ -307,7 +311,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
if (_clientEval)
{
var indexMap = new Dictionary();
- foreach (var item in projectionBindingExpression.IndexMap)
+ foreach (var item in projectionBindingExpression.IndexMap!)
{
indexMap[item.Key] = _selectExpression.AddToProjection(_existingProjections[item.Value]);
}
@@ -357,7 +361,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
protected override ElementInit VisitElementInit(ElementInit elementInit)
- => elementInit.Update(elementInit.Arguments.Select(e => MatchTypes(Visit(e), e.Type)));
+ => elementInit.Update(elementInit.Arguments.Select(e => MatchTypes(Visit(e)!, e.Type)));
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -395,10 +399,10 @@ protected override Expression VisitMember(MemberExpression memberExpression)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override MemberAssignment VisitMemberAssignment(MemberAssignment memberAssignment)
+ protected override MemberAssignment? VisitMemberAssignment(MemberAssignment memberAssignment)
{
var expression = memberAssignment.Expression;
- Expression visitedExpression;
+ Expression? visitedExpression;
if (_clientEval)
{
visitedExpression = Visit(memberAssignment.Expression);
@@ -417,7 +421,7 @@ protected override MemberAssignment VisitMemberAssignment(MemberAssignment membe
_projectionMembers.Pop();
}
- visitedExpression = MatchTypes(visitedExpression, expression.Type);
+ visitedExpression = MatchTypes(visitedExpression!, expression.Type);
return memberAssignment.Update(visitedExpression);
}
@@ -428,7 +432,7 @@ protected override MemberAssignment VisitMemberAssignment(MemberAssignment membe
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitMemberInit(MemberInitExpression memberInitExpression)
+ protected override Expression? VisitMemberInit(MemberInitExpression memberInitExpression)
{
Check.NotNull(memberInitExpression, nameof(memberInitExpression));
@@ -470,7 +474,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
for (var i = 0; i < methodCallExpression.Arguments.Count; i++)
{
var argument = methodCallExpression.Arguments[i];
- arguments[i] = MatchTypes(Visit(argument), argument.Type);
+ arguments[i] = MatchTypes(Visit(argument)!, argument.Type);
}
Expression updatedMethodCallExpression = methodCallExpression.Update(
@@ -501,7 +505,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- protected override Expression VisitNew(NewExpression newExpression)
+ protected override Expression? VisitNew(NewExpression newExpression)
{
Check.NotNull(newExpression, nameof(newExpression));
@@ -520,7 +524,7 @@ protected override Expression VisitNew(NewExpression newExpression)
for (var i = 0; i < newArguments.Length; i++)
{
var argument = newExpression.Arguments[i];
- Expression visitedArgument;
+ Expression? visitedArgument;
if (_clientEval)
{
visitedArgument = Visit(argument);
@@ -538,7 +542,7 @@ protected override Expression VisitNew(NewExpression newExpression)
_projectionMembers.Pop();
}
- newArguments[i] = MatchTypes(visitedArgument, argument.Type);
+ newArguments[i] = MatchTypes(visitedArgument!, argument.Type);
}
return newExpression.Update(newArguments);
@@ -551,7 +555,7 @@ protected override Expression VisitNew(NewExpression newExpression)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
protected override Expression VisitNewArray(NewArrayExpression newArrayExpression)
- => newArrayExpression.Update(newArrayExpression.Expressions.Select(e => MatchTypes(Visit(e), e.Type)));
+ => newArrayExpression.Update(newArrayExpression.Expressions.Select(e => MatchTypes(Visit(e)!, e.Type)));
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -561,7 +565,7 @@ protected override Expression VisitNewArray(NewArrayExpression newArrayExpressio
///
protected override Expression VisitUnary(UnaryExpression unaryExpression)
{
- var operand = Visit(unaryExpression.Operand);
+ var operand = Visit(unaryExpression.Operand)!;
return (unaryExpression.NodeType == ExpressionType.Convert
|| unaryExpression.NodeType == ExpressionType.ConvertChecked)
diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryCompilationContextFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryCompilationContextFactory.cs
index 58803ae45ee..ea0f6299e84 100644
--- a/src/EFCore.Relational/Query/Internal/RelationalQueryCompilationContextFactory.cs
+++ b/src/EFCore.Relational/Query/Internal/RelationalQueryCompilationContextFactory.cs
@@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryContextFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryContextFactory.cs
index a12db9f8a9c..dfcadfa66bd 100644
--- a/src/EFCore.Relational/Query/Internal/RelationalQueryContextFactory.cs
+++ b/src/EFCore.Relational/Query/Internal/RelationalQueryContextFactory.cs
@@ -4,6 +4,8 @@
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryMetadataExtractingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryMetadataExtractingExpressionVisitor.cs
index 474d5fb1565..52a21dd9872 100644
--- a/src/EFCore.Relational/Query/Internal/RelationalQueryMetadataExtractingExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/Internal/RelationalQueryMetadataExtractingExpressionVisitor.cs
@@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryStringFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryStringFactory.cs
index 9a8385c72ce..2661d889340 100644
--- a/src/EFCore.Relational/Query/Internal/RelationalQueryStringFactory.cs
+++ b/src/EFCore.Relational/Query/Internal/RelationalQueryStringFactory.cs
@@ -5,6 +5,8 @@
using System.Text;
using Microsoft.EntityFrameworkCore.Storage.Internal;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPostprocessorFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPostprocessorFactory.cs
index 4b40cf6ec4b..2bfbb6e95f1 100644
--- a/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPostprocessorFactory.cs
+++ b/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPostprocessorFactory.cs
@@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPreprocessorFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPreprocessorFactory.cs
index 3b5e1598e39..afc3911f30b 100644
--- a/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPreprocessorFactory.cs
+++ b/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPreprocessorFactory.cs
@@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryableMethodTranslatingExpressionVisitorFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryableMethodTranslatingExpressionVisitorFactory.cs
index 113add1e61f..bff41f31d18 100644
--- a/src/EFCore.Relational/Query/Internal/RelationalQueryableMethodTranslatingExpressionVisitorFactory.cs
+++ b/src/EFCore.Relational/Query/Internal/RelationalQueryableMethodTranslatingExpressionVisitorFactory.cs
@@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
diff --git a/src/EFCore.Relational/Query/Internal/RelationalShapedQueryCompilingExpressionVisitorFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalShapedQueryCompilingExpressionVisitorFactory.cs
index 35e030aeeec..5da1501d8d9 100644
--- a/src/EFCore.Relational/Query/Internal/RelationalShapedQueryCompilingExpressionVisitorFactory.cs
+++ b/src/EFCore.Relational/Query/Internal/RelationalShapedQueryCompilingExpressionVisitorFactory.cs
@@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
diff --git a/src/EFCore.Relational/Query/Internal/RelationalSqlTranslatingExpressionVisitorFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalSqlTranslatingExpressionVisitorFactory.cs
index a2626c17717..495fd9dfe00 100644
--- a/src/EFCore.Relational/Query/Internal/RelationalSqlTranslatingExpressionVisitorFactory.cs
+++ b/src/EFCore.Relational/Query/Internal/RelationalSqlTranslatingExpressionVisitorFactory.cs
@@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/Internal/RelationalValueConverterCompensatingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/RelationalValueConverterCompensatingExpressionVisitor.cs
index ad33ad59c90..b2848ef93a1 100644
--- a/src/EFCore.Relational/Query/Internal/RelationalValueConverterCompensatingExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/Internal/RelationalValueConverterCompensatingExpressionVisitor.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -152,7 +154,7 @@ private Expression VisitLeftJoin(LeftJoinExpression leftJoinExpression)
private SqlExpression TryCompensateForBoolWithValueConverter(SqlExpression sqlExpression)
{
if (sqlExpression is ColumnExpression columnExpression
- && columnExpression.TypeMapping.ClrType == typeof(bool)
+ && columnExpression.TypeMapping!.ClrType == typeof(bool)
&& columnExpression.TypeMapping.Converter != null)
{
return _sqlExpressionFactory.Equal(
diff --git a/src/EFCore.Relational/Query/Internal/ResultContext.cs b/src/EFCore.Relational/Query/Internal/ResultContext.cs
index 95614f75ef9..5cb9f7c7e6a 100644
--- a/src/EFCore.Relational/Query/Internal/ResultContext.cs
+++ b/src/EFCore.Relational/Query/Internal/ResultContext.cs
@@ -3,6 +3,8 @@
using JetBrains.Annotations;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -19,6 +21,6 @@ public class ResultContext
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual object[] Values { get; [param: NotNull] set; }
+ public virtual object[]? Values { get; [param: CanBeNull] set; }
}
}
diff --git a/src/EFCore.Relational/Query/Internal/SelectExpressionProjectionApplyingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/SelectExpressionProjectionApplyingExpressionVisitor.cs
index e80aa3f2f29..82e1d5076f1 100644
--- a/src/EFCore.Relational/Query/Internal/SelectExpressionProjectionApplyingExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/Internal/SelectExpressionProjectionApplyingExpressionVisitor.cs
@@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
diff --git a/src/EFCore.Relational/Query/Internal/SelectExpressionPruningExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/SelectExpressionPruningExpressionVisitor.cs
index a7675c60d70..0ac48718fb4 100644
--- a/src/EFCore.Relational/Query/Internal/SelectExpressionPruningExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/Internal/SelectExpressionPruningExpressionVisitor.cs
@@ -3,6 +3,9 @@
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
+using CA = System.Diagnostics.CodeAnalysis;
+
+#nullable enable
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
@@ -20,7 +23,8 @@ public class SelectExpressionPruningExpressionVisitor : ExpressionVisitor
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public override Expression Visit(Expression expression)
+ [return: CA.NotNullIfNotNull("expression")]
+ public override Expression? Visit(Expression? expression)
{
switch (expression)
{
diff --git a/src/EFCore.Relational/Query/Internal/SingleQueryCollectionContext.cs b/src/EFCore.Relational/Query/Internal/SingleQueryCollectionContext.cs
index bd764db8394..51251a0a91a 100644
--- a/src/EFCore.Relational/Query/Internal/SingleQueryCollectionContext.cs
+++ b/src/EFCore.Relational/Query/Internal/SingleQueryCollectionContext.cs
@@ -3,6 +3,8 @@
using JetBrains.Annotations;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -20,8 +22,8 @@ public class SingleQueryCollectionContext
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
public SingleQueryCollectionContext(
- [CanBeNull] object parent,
- [NotNull] object collection,
+ [CanBeNull] object? parent,
+ [CanBeNull] object? collection,
[NotNull] object[] parentIdentifier,
[NotNull] object[] outerIdentifier)
{
@@ -30,6 +32,7 @@ public SingleQueryCollectionContext(
ParentIdentifier = parentIdentifier;
OuterIdentifier = outerIdentifier;
ResultContext = new ResultContext();
+ SelfIdentifier = null!;
}
///
@@ -46,7 +49,7 @@ public SingleQueryCollectionContext(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual object Parent { get; }
+ public virtual object? Parent { get; }
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -54,7 +57,7 @@ public SingleQueryCollectionContext(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual object Collection { get; }
+ public virtual object? Collection { get; }
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -78,7 +81,7 @@ public SingleQueryCollectionContext(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual object[] SelfIdentifier { get; private set; }
+ public virtual object[]? SelfIdentifier { get; private set; }
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -86,7 +89,7 @@ public SingleQueryCollectionContext(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual void UpdateSelfIdentifier([NotNull] object[] selfIdentifier)
+ public virtual void UpdateSelfIdentifier([CanBeNull] object[]? selfIdentifier)
{
SelfIdentifier = selfIdentifier;
}
diff --git a/src/EFCore.Relational/Query/Internal/SingleQueryResultCoordinator.cs b/src/EFCore.Relational/Query/Internal/SingleQueryResultCoordinator.cs
index f23908c949a..2eb92be3f71 100644
--- a/src/EFCore.Relational/Query/Internal/SingleQueryResultCoordinator.cs
+++ b/src/EFCore.Relational/Query/Internal/SingleQueryResultCoordinator.cs
@@ -4,6 +4,8 @@
using System.Collections.Generic;
using JetBrains.Annotations;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -55,7 +57,7 @@ public SingleQueryResultCoordinator()
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual IList Collections { get; } = new List();
+ public virtual IList Collections { get; } = new List();
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
diff --git a/src/EFCore.Relational/Query/Internal/SingleQueryingEnumerable.cs b/src/EFCore.Relational/Query/Internal/SingleQueryingEnumerable.cs
index 570382f50eb..a5422ee1ad6 100644
--- a/src/EFCore.Relational/Query/Internal/SingleQueryingEnumerable.cs
+++ b/src/EFCore.Relational/Query/Internal/SingleQueryingEnumerable.cs
@@ -12,6 +12,8 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -122,8 +124,8 @@ private sealed class Enumerator : IEnumerator
private readonly bool _standAloneStateManager;
private readonly bool _detailedErrorsEnabled;
- private RelationalDataReader _dataReader;
- private SingleQueryResultCoordinator _resultCoordinator;
+ private RelationalDataReader? _dataReader;
+ private SingleQueryResultCoordinator? _resultCoordinator;
public Enumerator(SingleQueryingEnumerable queryingEnumerable)
{
@@ -134,12 +136,13 @@ public Enumerator(SingleQueryingEnumerable queryingEnumerable)
_queryLogger = queryingEnumerable._queryLogger;
_standAloneStateManager = queryingEnumerable._standAloneStateManager;
_detailedErrorsEnabled = queryingEnumerable._detailedErrorsEnabled;
+ Current = default!;
}
public T Current { get; private set; }
object IEnumerator.Current
- => Current;
+ => Current!;
public bool MoveNext()
{
@@ -153,8 +156,8 @@ public bool MoveNext()
.Execute(true, InitializeReader, null);
}
- var hasNext = _resultCoordinator.HasNext ?? _dataReader.Read();
- Current = default;
+ var hasNext = _resultCoordinator!.HasNext ?? _dataReader!.Read();
+ Current = default!;
if (hasNext)
{
@@ -163,7 +166,7 @@ public bool MoveNext()
_resultCoordinator.ResultReady = true;
_resultCoordinator.HasNext = null;
Current = _shaper(
- _relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext,
+ _relationalQueryContext, _dataReader!.DbDataReader, _resultCoordinator.ResultContext,
_resultCoordinator);
if (_resultCoordinator.ResultReady)
{
@@ -239,8 +242,8 @@ private sealed class AsyncEnumerator : IAsyncEnumerator
private readonly bool _standAloneStateManager;
private readonly bool _detailedErrorsEnabled;
- private RelationalDataReader _dataReader;
- private SingleQueryResultCoordinator _resultCoordinator;
+ private RelationalDataReader? _dataReader;
+ private SingleQueryResultCoordinator? _resultCoordinator;
public AsyncEnumerator(SingleQueryingEnumerable queryingEnumerable)
{
@@ -251,6 +254,7 @@ public AsyncEnumerator(SingleQueryingEnumerable queryingEnumerable)
_queryLogger = queryingEnumerable._queryLogger;
_standAloneStateManager = queryingEnumerable._standAloneStateManager;
_detailedErrorsEnabled = queryingEnumerable._detailedErrorsEnabled;
+ Current = default!;
}
public T Current { get; private set; }
@@ -268,9 +272,9 @@ await _relationalQueryContext.ExecutionStrategyFactory.Create()
.ConfigureAwait(false);
}
- var hasNext = _resultCoordinator.HasNext
- ?? await _dataReader.ReadAsync(_relationalQueryContext.CancellationToken).ConfigureAwait(false);
- Current = default;
+ var hasNext = _resultCoordinator!.HasNext
+ ?? await _dataReader!.ReadAsync(_relationalQueryContext.CancellationToken).ConfigureAwait(false);
+ Current = default!;
if (hasNext)
{
@@ -279,7 +283,7 @@ await _relationalQueryContext.ExecutionStrategyFactory.Create()
_resultCoordinator.ResultReady = true;
_resultCoordinator.HasNext = null;
Current = _shaper(
- _relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext,
+ _relationalQueryContext, _dataReader!.DbDataReader, _resultCoordinator.ResultContext,
_resultCoordinator);
if (_resultCoordinator.ResultReady)
{
diff --git a/src/EFCore.Relational/Query/Internal/SplitIncludeRewritingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/SplitIncludeRewritingExpressionVisitor.cs
index d0775af8709..d51ac64462e 100644
--- a/src/EFCore.Relational/Query/Internal/SplitIncludeRewritingExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/Internal/SplitIncludeRewritingExpressionVisitor.cs
@@ -6,6 +6,8 @@
using System.Linq;
using System.Linq.Expressions;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -76,7 +78,7 @@ private LambdaExpression RewriteCollectionInclude(
{
var selectorParameter = selector.Parameters[0];
var selectorBody = selector.Body;
- var sourceElementType = source.Type.TryGetSequenceType();
+ var sourceElementType = source.Type.TryGetSequenceType()!;
if (reverseOrdering)
{
diff --git a/src/EFCore.Relational/Query/Internal/SplitQueryCollectionContext.cs b/src/EFCore.Relational/Query/Internal/SplitQueryCollectionContext.cs
index 4a20f14237b..6ef8f622f84 100644
--- a/src/EFCore.Relational/Query/Internal/SplitQueryCollectionContext.cs
+++ b/src/EFCore.Relational/Query/Internal/SplitQueryCollectionContext.cs
@@ -3,6 +3,8 @@
using JetBrains.Annotations;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -20,8 +22,8 @@ public class SplitQueryCollectionContext
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
public SplitQueryCollectionContext(
- [CanBeNull] object parent,
- [NotNull] object collection,
+ [CanBeNull] object? parent,
+ [CanBeNull] object? collection,
[NotNull] object[] parentIdentifier)
{
Parent = parent;
@@ -44,7 +46,7 @@ public SplitQueryCollectionContext(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual object Parent { get; }
+ public virtual object? Parent { get; }
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -52,7 +54,7 @@ public SplitQueryCollectionContext(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual object Collection { get; }
+ public virtual object? Collection { get; }
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
diff --git a/src/EFCore.Relational/Query/Internal/SplitQueryDataReaderContext.cs b/src/EFCore.Relational/Query/Internal/SplitQueryDataReaderContext.cs
index 16d38476f8a..64e0129981d 100644
--- a/src/EFCore.Relational/Query/Internal/SplitQueryDataReaderContext.cs
+++ b/src/EFCore.Relational/Query/Internal/SplitQueryDataReaderContext.cs
@@ -4,6 +4,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Storage;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
diff --git a/src/EFCore.Relational/Query/Internal/SplitQueryResultCoordinator.cs b/src/EFCore.Relational/Query/Internal/SplitQueryResultCoordinator.cs
index ecf50d062ed..900f8aec4b2 100644
--- a/src/EFCore.Relational/Query/Internal/SplitQueryResultCoordinator.cs
+++ b/src/EFCore.Relational/Query/Internal/SplitQueryResultCoordinator.cs
@@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Storage;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -40,7 +42,7 @@ public SplitQueryResultCoordinator()
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual IList Collections { get; } = new List();
+ public virtual IList Collections { get; } = new List();
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -48,7 +50,7 @@ public SplitQueryResultCoordinator()
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public virtual IList DataReaders { get; } = new List();
+ public virtual IList DataReaders { get; } = new List();
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
diff --git a/src/EFCore.Relational/Query/Internal/SplitQueryingEnumerable.cs b/src/EFCore.Relational/Query/Internal/SplitQueryingEnumerable.cs
index e1763674f72..a9e0c25a83c 100644
--- a/src/EFCore.Relational/Query/Internal/SplitQueryingEnumerable.cs
+++ b/src/EFCore.Relational/Query/Internal/SplitQueryingEnumerable.cs
@@ -12,6 +12,8 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -130,9 +132,9 @@ private sealed class Enumerator : IEnumerator
private readonly bool _standAloneStateManager;
private readonly bool _detailedErrorsEnabled;
- private RelationalDataReader _dataReader;
- private SplitQueryResultCoordinator _resultCoordinator;
- private IExecutionStrategy _executionStrategy;
+ private RelationalDataReader? _dataReader;
+ private SplitQueryResultCoordinator? _resultCoordinator;
+ private IExecutionStrategy? _executionStrategy;
public Enumerator(SplitQueryingEnumerable queryingEnumerable)
{
@@ -144,12 +146,13 @@ public Enumerator(SplitQueryingEnumerable queryingEnumerable)
_queryLogger = queryingEnumerable._queryLogger;
_standAloneStateManager = queryingEnumerable._standAloneStateManager;
_detailedErrorsEnabled = queryingEnumerable._detailedErrorsEnabled;
+ Current = default!;
}
public T Current { get; private set; }
object IEnumerator.Current
- => Current;
+ => Current!;
public bool MoveNext()
{
@@ -167,15 +170,15 @@ public bool MoveNext()
_executionStrategy.Execute(true, InitializeReader, null);
}
- var hasNext = _dataReader.Read();
- Current = default;
+ var hasNext = _dataReader!.Read();
+ Current = default!;
if (hasNext)
{
- _resultCoordinator.ResultContext.Values = null;
+ _resultCoordinator!.ResultContext.Values = null;
_shaper(
_relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext, _resultCoordinator);
- _relatedDataLoaders?.Invoke(_relationalQueryContext, _executionStrategy, _resultCoordinator);
+ _relatedDataLoaders?.Invoke(_relationalQueryContext, _executionStrategy!, _resultCoordinator);
Current = _shaper(
_relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext, _resultCoordinator);
}
@@ -216,12 +219,17 @@ private bool InitializeReader(DbContext _, bool result)
public void Dispose()
{
_dataReader?.Dispose();
- foreach (var dataReader in _resultCoordinator.DataReaders)
+ if (_resultCoordinator != null)
{
- dataReader?.DataReader.Dispose();
- }
+ foreach (var dataReader in _resultCoordinator.DataReaders)
+ {
+ dataReader?.DataReader.Dispose();
+ }
+
+ _resultCoordinator.DataReaders.Clear();
- _resultCoordinator.DataReaders.Clear();
+ _resultCoordinator = null;
+ }
_dataReader = null;
}
@@ -241,9 +249,9 @@ private sealed class AsyncEnumerator : IAsyncEnumerator
private readonly bool _standAloneStateManager;
private readonly bool _detailedErrorEnabled;
- private RelationalDataReader _dataReader;
- private SplitQueryResultCoordinator _resultCoordinator;
- private IExecutionStrategy _executionStrategy;
+ private RelationalDataReader? _dataReader;
+ private SplitQueryResultCoordinator? _resultCoordinator;
+ private IExecutionStrategy? _executionStrategy;
public AsyncEnumerator(SplitQueryingEnumerable queryingEnumerable)
{
@@ -255,6 +263,7 @@ public AsyncEnumerator(SplitQueryingEnumerable queryingEnumerable)
_queryLogger = queryingEnumerable._queryLogger;
_standAloneStateManager = queryingEnumerable._standAloneStateManager;
_detailedErrorEnabled = queryingEnumerable._detailedErrorsEnabled;
+ Current = default!;
}
public T Current { get; private set; }
@@ -276,17 +285,17 @@ await _executionStrategy.ExecuteAsync(
true, InitializeReaderAsync, null, _relationalQueryContext.CancellationToken).ConfigureAwait(false);
}
- var hasNext = await _dataReader.ReadAsync(_relationalQueryContext.CancellationToken).ConfigureAwait(false);
- Current = default;
+ var hasNext = await _dataReader!.ReadAsync(_relationalQueryContext.CancellationToken).ConfigureAwait(false);
+ Current = default!;
if (hasNext)
{
- _resultCoordinator.ResultContext.Values = null;
+ _resultCoordinator!.ResultContext.Values = null;
_shaper(
_relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext, _resultCoordinator);
if (_relatedDataLoaders != null)
{
- await _relatedDataLoaders(_relationalQueryContext, _executionStrategy, _resultCoordinator)
+ await _relatedDataLoaders(_relationalQueryContext, _executionStrategy!, _resultCoordinator)
.ConfigureAwait(false);
}
@@ -334,16 +343,19 @@ public async ValueTask DisposeAsync()
if (_dataReader != null)
{
await _dataReader.DisposeAsync().ConfigureAwait(false);
- foreach (var dataReader in _resultCoordinator.DataReaders)
+ if (_resultCoordinator != null)
{
- if (dataReader != null)
+ foreach (var dataReader in _resultCoordinator.DataReaders)
{
- await dataReader.DataReader.DisposeAsync().ConfigureAwait(false);
+ if (dataReader != null)
+ {
+ await dataReader.DataReader.DisposeAsync().ConfigureAwait(false);
+ }
}
- }
-
- _resultCoordinator.DataReaders.Clear();
+ _resultCoordinator.DataReaders.Clear();
+ _resultCoordinator = null;
+ }
_dataReader = null;
}
}
diff --git a/src/EFCore.Relational/Query/Internal/SqlExpressionOptimizingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/SqlExpressionOptimizingExpressionVisitor.cs
index c4575af10cb..a759673ff8d 100644
--- a/src/EFCore.Relational/Query/Internal/SqlExpressionOptimizingExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/Internal/SqlExpressionOptimizingExpressionVisitor.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -138,7 +140,7 @@ private Expression VisitSqlUnary([NotNull] SqlUnaryExpression sqlUnaryExpression
sqlUnaryExpression.OperatorType,
newOperand,
sqlUnaryExpression.Type,
- sqlUnaryExpression.TypeMapping);
+ sqlUnaryExpression.TypeMapping!);
}
private SqlExpression SimplifyUnaryExpression(
@@ -198,7 +200,7 @@ private SqlExpression SimplifyUnaryExpression(
: ExpressionType.AndAlso,
newLeft,
newRight,
- binaryOperand.TypeMapping);
+ binaryOperand.TypeMapping!);
}
// those optimizations are only valid in 2-value logic
@@ -211,7 +213,7 @@ private SqlExpression SimplifyUnaryExpression(
negated,
binaryOperand.Left,
binaryOperand.Right,
- binaryOperand.TypeMapping);
+ binaryOperand.TypeMapping!);
}
}
break;
@@ -229,7 +231,7 @@ private SqlExpression SimplifyUnaryExpression(
typeMapping);
}
- return _sqlExpressionFactory.MakeUnary(operatorType, operand, type, typeMapping);
+ return _sqlExpressionFactory.MakeUnary(operatorType, operand, type, typeMapping)!;
}
private SqlExpression SimplifyNullNotNullExpression(
@@ -304,6 +306,7 @@ private SqlExpression SimplifyNullNotNullExpression(
case SqlFunctionExpression sqlFunctionExpression
when sqlFunctionExpression.IsBuiltIn
+ && sqlFunctionExpression.Arguments != null
&& string.Equals("COALESCE", sqlFunctionExpression.Name, StringComparison.OrdinalIgnoreCase):
// for coalesce:
// (a ?? b) == null -> a == null && b == null
@@ -325,7 +328,7 @@ when sqlFunctionExpression.IsBuiltIn
break;
}
- return _sqlExpressionFactory.MakeUnary(operatorType, operand, type, typeMapping);
+ return _sqlExpressionFactory.MakeUnary(operatorType, operand, type, typeMapping)!;
}
private Expression VisitSqlBinary([NotNull] SqlBinaryExpression sqlBinaryExpression)
@@ -337,7 +340,7 @@ private Expression VisitSqlBinary([NotNull] SqlBinaryExpression sqlBinaryExpress
sqlBinaryExpression.OperatorType,
newLeft,
newRight,
- sqlBinaryExpression.TypeMapping);
+ sqlBinaryExpression.TypeMapping!);
}
private SqlExpression SimplifyBinaryExpression(
@@ -418,7 +421,7 @@ private SqlExpression SimplifyBinaryExpression(
break;
}
- return _sqlExpressionFactory.MakeBinary(operatorType, left, right, typeMapping);
+ return _sqlExpressionFactory.MakeBinary(operatorType, left, right, typeMapping)!;
}
private SqlExpression SimplifyNullComparisonExpression(
@@ -448,15 +451,15 @@ private SqlExpression SimplifyNullComparisonExpression(
}
}
- return _sqlExpressionFactory.MakeBinary(operatorType, left, right, typeMapping);
+ return _sqlExpressionFactory.MakeBinary(operatorType, left, right, typeMapping)!;
}
private SqlExpression SimplifyBoolConstantComparisonExpression(
ExpressionType operatorType,
SqlExpression left,
SqlExpression right,
- SqlConstantExpression leftBoolConstant,
- SqlConstantExpression rightBoolConstant,
+ SqlConstantExpression? leftBoolConstant,
+ SqlConstantExpression? rightBoolConstant,
RelationalTypeMapping typeMapping)
{
if (leftBoolConstant != null && rightBoolConstant != null)
@@ -500,7 +503,7 @@ private SqlExpression SimplifyBoolConstantComparisonExpression(
: right;
}
- return _sqlExpressionFactory.MakeBinary(operatorType, left, right, typeMapping);
+ return _sqlExpressionFactory.MakeBinary(operatorType, left, right, typeMapping)!;
static bool CanOptimize(SqlExpression operand)
=> operand is LikeExpression
@@ -547,7 +550,7 @@ private SqlExpression SimplifyLogicalSqlBinaryExpression(
: left;
}
- return _sqlExpressionFactory.MakeBinary(operatorType, left, right, typeMapping);
+ return _sqlExpressionFactory.MakeBinary(operatorType, left, right, typeMapping)!;
}
}
}
diff --git a/src/EFCore.Relational/Query/Internal/SqlExpressionSimplifyingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/SqlExpressionSimplifyingExpressionVisitor.cs
index e7f06449104..a2b71fb6f22 100644
--- a/src/EFCore.Relational/Query/Internal/SqlExpressionSimplifyingExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/Internal/SqlExpressionSimplifyingExpressionVisitor.cs
@@ -9,6 +9,9 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+using CA = System.Diagnostics.CodeAnalysis;
+
+#nullable enable
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
@@ -68,7 +71,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
return base.VisitExtension(extensionExpression);
}
- private bool IsCompareTo(CaseExpression caseExpression)
+ private bool IsCompareTo([CA.NotNullWhen(true)] CaseExpression? caseExpression)
{
if (caseExpression != null
&& caseExpression.Operand == null
@@ -233,10 +236,8 @@ private Expression SimplifySqlBinary(SqlBinaryExpression sqlBinaryExpression)
if (sqlBinaryExpression.OperatorType == ExpressionType.AndAlso
|| sqlBinaryExpression.OperatorType == ExpressionType.OrElse)
{
- var leftCandidateInfo = GetInExressionCandidateInfo(left);
- var rightCandidateInfo = GetInExressionCandidateInfo(right);
- if (leftCandidateInfo.OptimizeCandidate
- && rightCandidateInfo.OptimizeCandidate
+ if (TryGetInExressionCandidateInfo(left, out var leftCandidateInfo)
+ && TryGetInExressionCandidateInfo(right, out var rightCandidateInfo)
&& leftCandidateInfo.ColumnExpression == rightCandidateInfo.ColumnExpression
&& leftCandidateInfo.OperationType == rightCandidateInfo.OperationType)
{
@@ -374,29 +375,32 @@ private List
- public override Expression Visit(Expression expression)
+ [return: CA.NotNullIfNotNull("expression")]
+ public override Expression? Visit(Expression? expression)
{
switch (expression)
{
diff --git a/src/EFCore.Relational/Query/Internal/TableValuedFunctionQueryRootExpression.cs b/src/EFCore.Relational/Query/Internal/TableValuedFunctionQueryRootExpression.cs
index f5dc38a7437..7ca31589ab3 100644
--- a/src/EFCore.Relational/Query/Internal/TableValuedFunctionQueryRootExpression.cs
+++ b/src/EFCore.Relational/Query/Internal/TableValuedFunctionQueryRootExpression.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
@@ -99,7 +101,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is TableValuedFunctionQueryRootExpression queryRootExpression
diff --git a/src/EFCore.Relational/Query/Internal/TableValuedFunctionToQueryRootConvertingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/TableValuedFunctionToQueryRootConvertingExpressionVisitor.cs
index 5eb954193ce..ed098c8051a 100644
--- a/src/EFCore.Relational/Query/Internal/TableValuedFunctionToQueryRootConvertingExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/Internal/TableValuedFunctionToQueryRootConvertingExpressionVisitor.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.Internal
{
///
diff --git a/src/EFCore.Relational/Query/QuerySqlGenerator.cs b/src/EFCore.Relational/Query/QuerySqlGenerator.cs
index 8018d64af5e..6f8a7f60249 100644
--- a/src/EFCore.Relational/Query/QuerySqlGenerator.cs
+++ b/src/EFCore.Relational/Query/QuerySqlGenerator.cs
@@ -12,6 +12,8 @@
using Microsoft.EntityFrameworkCore.Storage.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
@@ -60,6 +62,7 @@ public QuerySqlGenerator([NotNull] QuerySqlGeneratorDependencies dependencies)
_relationalCommandBuilderFactory = dependencies.RelationalCommandBuilderFactory;
_sqlGenerationHelper = dependencies.SqlGenerationHelper;
+ _relationalCommandBuilder = default!;
}
///
@@ -163,7 +166,7 @@ protected override Expression VisitSelect(SelectExpression selectExpression)
return selectExpression;
}
- IDisposable subQueryIndent = null;
+ IDisposable? subQueryIndent = null;
if (selectExpression.Alias != null)
{
@@ -226,7 +229,7 @@ protected override Expression VisitSelect(SelectExpression selectExpression)
if (selectExpression.Alias != null)
{
- subQueryIndent.Dispose();
+ subQueryIndent!.Dispose();
_relationalCommandBuilder.AppendLine()
.Append(")" + AliasSeparator + _sqlGenerationHelper.DelimitIdentifier(selectExpression.Alias));
@@ -289,7 +292,7 @@ protected override Expression VisitSqlFunction(SqlFunctionExpression sqlFunction
if (!sqlFunctionExpression.IsNiladic)
{
_relationalCommandBuilder.Append("(");
- GenerateList(sqlFunctionExpression.Arguments, e => Visit(e));
+ GenerateList(sqlFunctionExpression.Arguments!, e => Visit(e));
_relationalCommandBuilder.Append(")");
}
@@ -351,7 +354,7 @@ protected override Expression VisitTable(TableExpression tableExpression)
private void GenerateFromSql(FromSqlExpression fromSqlExpression)
{
var sql = fromSqlExpression.Sql;
- string[] substitutions = null;
+ string[]? substitutions = null;
switch (fromSqlExpression.Arguments)
{
@@ -384,7 +387,7 @@ private void GenerateFromSql(FromSqlExpression fromSqlExpression)
}
else if (value is SqlConstantExpression sqlConstantExpression)
{
- substitutions[i] = sqlConstantExpression.TypeMapping.GenerateSqlLiteral(sqlConstantExpression.Value);
+ substitutions[i] = sqlConstantExpression.TypeMapping!.GenerateSqlLiteral(sqlConstantExpression.Value);
}
}
@@ -551,7 +554,7 @@ protected override Expression VisitSqlConstant(SqlConstantExpression sqlConstant
Check.NotNull(sqlConstantExpression, nameof(sqlConstantExpression));
_relationalCommandBuilder
- .Append(sqlConstantExpression.TypeMapping.GenerateSqlLiteral(sqlConstantExpression.Value));
+ .Append(sqlConstantExpression.TypeMapping!.GenerateSqlLiteral(sqlConstantExpression.Value));
return sqlConstantExpression;
}
@@ -710,7 +713,7 @@ protected override Expression VisitSqlUnary(SqlUnaryExpression sqlUnaryExpressio
}
_relationalCommandBuilder.Append(" AS ");
- _relationalCommandBuilder.Append(sqlUnaryExpression.TypeMapping.StoreType);
+ _relationalCommandBuilder.Append(sqlUnaryExpression.TypeMapping!.StoreType);
_relationalCommandBuilder.Append(")");
break;
}
@@ -924,7 +927,7 @@ protected virtual void GenerateLimitOffset([NotNull] SelectExpression selectExpr
private void GenerateList(
IReadOnlyList items,
Action generationAction,
- Action joinAction = null)
+ Action? joinAction = null)
{
joinAction ??= (isb => isb.Append(", "));
diff --git a/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs b/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs
index 5a6d78f67ca..f9a5a4ca9e9 100644
--- a/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs
+++ b/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs b/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs
index 1b36d90cb37..4b349e0037a 100644
--- a/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs
+++ b/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
@@ -66,11 +68,11 @@ public RelationalCollectionShaperExpression(
[NotNull] Expression parentIdentifier,
[NotNull] Expression outerIdentifier,
[NotNull] Expression selfIdentifier,
- [CanBeNull] IReadOnlyList parentIdentifierValueComparers,
- [CanBeNull] IReadOnlyList outerIdentifierValueComparers,
- [CanBeNull] IReadOnlyList selfIdentifierValueComparers,
+ [CanBeNull] IReadOnlyList? parentIdentifierValueComparers,
+ [CanBeNull] IReadOnlyList? outerIdentifierValueComparers,
+ [CanBeNull] IReadOnlyList? selfIdentifierValueComparers,
[NotNull] Expression innerShaper,
- [CanBeNull] INavigationBase navigation,
+ [CanBeNull] INavigationBase? navigation,
[NotNull] Type elementType)
{
Check.NotNull(parentIdentifier, nameof(parentIdentifier));
@@ -114,17 +116,17 @@ public RelationalCollectionShaperExpression(
///
/// The list of value comparers to compare parent identifier.
///
- public virtual IReadOnlyList ParentIdentifierValueComparers { get; }
+ public virtual IReadOnlyList? ParentIdentifierValueComparers { get; }
///
/// The list of value comparers to compare outer identifier.
///
- public virtual IReadOnlyList OuterIdentifierValueComparers { get; }
+ public virtual IReadOnlyList? OuterIdentifierValueComparers { get; }
///
/// The list of value comparers to compare self identifier.
///
- public virtual IReadOnlyList SelfIdentifierValueComparers { get; }
+ public virtual IReadOnlyList? SelfIdentifierValueComparers { get; }
///
/// The expression to create inner elements.
@@ -134,7 +136,7 @@ public RelationalCollectionShaperExpression(
///
/// The navigation if associated with the collection.
///
- public virtual INavigationBase Navigation { get; }
+ public virtual INavigationBase? Navigation { get; }
///
/// The clr type of elements of the collection.
diff --git a/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGenerator.cs b/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGenerator.cs
index fc445de8776..cca003b9888 100644
--- a/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGenerator.cs
+++ b/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGenerator.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
@@ -121,7 +123,7 @@ public RelationalCompiledQueryCacheKey(
/// if the object is a and is for the same query,
/// otherwise .
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj is RelationalCompiledQueryCacheKey key
&& Equals(key);
diff --git a/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs b/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs
index cc05d4b58ce..ec1298e806a 100644
--- a/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs
+++ b/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs b/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs
index faeb57393f0..9e4354f33e3 100644
--- a/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs
+++ b/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs
@@ -14,6 +14,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
@@ -53,7 +55,7 @@ protected RelationalEntityShaperExpression(
[NotNull] IEntityType entityType,
[NotNull] Expression valueBufferExpression,
bool nullable,
- [CanBeNull] LambdaExpression materializationCondition)
+ [CanBeNull] LambdaExpression? materializationCondition)
: base(entityType, valueBufferExpression, nullable, materializationCondition)
{
}
@@ -106,7 +108,7 @@ protected override LambdaExpression GenerateMaterializationCondition(IEntityType
// Optional dependent
var body = baseCondition.Body;
var valueBufferParameter = baseCondition.Parameters[0];
- Expression condition = null;
+ Expression? condition = null;
var requiredNonPkProperties = entityType.GetProperties().Where(p => !p.IsNullable && !p.IsPrimaryKey()).ToList();
if (requiredNonPkProperties.Count > 0)
{
diff --git a/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilter.cs b/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilter.cs
index c2027496d3b..6fdd0e07856 100644
--- a/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilter.cs
+++ b/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilter.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilterDependencies.cs b/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilterDependencies.cs
index 0fad0324095..a871fda6bcd 100644
--- a/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilterDependencies.cs
+++ b/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilterDependencies.cs
@@ -4,6 +4,8 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs b/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs
index 9dabcb3d67a..89e92a68ab7 100644
--- a/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs
+++ b/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs
@@ -13,6 +13,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
@@ -46,8 +48,8 @@ public RelationalMemberTranslatorProvider([NotNull] RelationalMemberTranslatorPr
}
///
- public virtual SqlExpression Translate(
- SqlExpression instance,
+ public virtual SqlExpression? Translate(
+ SqlExpression? instance,
MemberInfo member,
Type returnType,
IDiagnosticsLogger logger)
diff --git a/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs b/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs
index 8c9d9645383..721800b2c1d 100644
--- a/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs
+++ b/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs
index 021106267e1..e29090f3798 100644
--- a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs
+++ b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs
@@ -14,6 +14,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
@@ -62,9 +64,9 @@ public RelationalMethodCallTranslatorProvider([NotNull] RelationalMethodCallTran
}
///
- public virtual SqlExpression Translate(
+ public virtual SqlExpression? Translate(
IModel model,
- SqlExpression instance,
+ SqlExpression? instance,
MethodInfo method,
IReadOnlyList arguments,
IDiagnosticsLogger logger)
diff --git a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs
index a745acc0d14..ef87364bbdd 100644
--- a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs
+++ b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessor.cs b/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessor.cs
index 7e0cbd09702..6048f2d7ee5 100644
--- a/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessor.cs
+++ b/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessor.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessorDependencies.cs b/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessorDependencies.cs
index df7bdd9d1f8..0a322657104 100644
--- a/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessorDependencies.cs
+++ b/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessorDependencies.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalQueryCompilationContext.cs b/src/EFCore.Relational/Query/RelationalQueryCompilationContext.cs
index 839a0fd92bc..0d7ef88fc1c 100644
--- a/src/EFCore.Relational/Query/RelationalQueryCompilationContext.cs
+++ b/src/EFCore.Relational/Query/RelationalQueryCompilationContext.cs
@@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalQueryCompilationContextDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryCompilationContextDependencies.cs
index c0ace001fa7..5ad66d1907f 100644
--- a/src/EFCore.Relational/Query/RelationalQueryCompilationContextDependencies.cs
+++ b/src/EFCore.Relational/Query/RelationalQueryCompilationContextDependencies.cs
@@ -4,6 +4,8 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalQueryContext.cs b/src/EFCore.Relational/Query/RelationalQueryContext.cs
index fe2bc4fdb47..cfe401d3f5a 100644
--- a/src/EFCore.Relational/Query/RelationalQueryContext.cs
+++ b/src/EFCore.Relational/Query/RelationalQueryContext.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs
index 45dbb531eda..1f30abaebe7 100644
--- a/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs
+++ b/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs
index 349e253e1ed..fbc96760bca 100644
--- a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs
+++ b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs
index fe7a2e80f62..70b0f9df8f5 100644
--- a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs
+++ b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessor.cs b/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessor.cs
index bfb11480cfd..7632a570143 100644
--- a/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessor.cs
+++ b/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessor.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessorDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessorDependencies.cs
index 51e2b41f256..d7f877d3a70 100644
--- a/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessorDependencies.cs
+++ b/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessorDependencies.cs
@@ -4,6 +4,8 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs
index dac3deb55ab..5cf720ed993 100644
--- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs
@@ -16,6 +16,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
@@ -25,7 +27,6 @@ public class RelationalQueryableMethodTranslatingExpressionVisitor : QueryableMe
private readonly WeakEntityExpandingExpressionVisitor _weakEntityExpandingExpressionVisitor;
private readonly RelationalProjectionBindingExpressionVisitor _projectionBindingExpressionVisitor;
private readonly QueryCompilationContext _queryCompilationContext;
- private readonly IModel _model;
private readonly ISqlExpressionFactory _sqlExpressionFactory;
private readonly bool _subquery;
@@ -49,7 +50,6 @@ public RelationalQueryableMethodTranslatingExpressionVisitor(
var sqlExpressionFactory = relationalDependencies.SqlExpressionFactory;
_queryCompilationContext = queryCompilationContext;
- _model = queryCompilationContext.Model;
_sqlTranslator = relationalDependencies.RelationalSqlTranslatingExpressionVisitorFactory.Create(queryCompilationContext, this);
_weakEntityExpandingExpressionVisitor = new WeakEntityExpandingExpressionVisitor(_sqlTranslator, sqlExpressionFactory);
_projectionBindingExpressionVisitor = new RelationalProjectionBindingExpressionVisitor(this, _sqlTranslator);
@@ -82,7 +82,7 @@ protected RelationalQueryableMethodTranslatingExpressionVisitor(
}
///
- protected override Expression VisitExtension(Expression extensionExpression)
+ protected override Expression? VisitExtension(Expression extensionExpression)
{
switch (extensionExpression)
{
@@ -159,7 +159,7 @@ protected override ShapedQueryExpression CreateShapedQueryExpression(Type elemen
{
Check.NotNull(elementType, nameof(elementType));
- var entityType = _queryCompilationContext.Model.FindEntityType(elementType);
+ var entityType = _queryCompilationContext.Model.FindEntityType(elementType)!;
var queryExpression = _sqlExpressionFactory.Select(entityType);
return CreateShapedQueryExpression(entityType, queryExpression);
@@ -185,7 +185,7 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent
false));
///
- protected override ShapedQueryExpression TranslateAll(ShapedQueryExpression source, LambdaExpression predicate)
+ protected override ShapedQueryExpression? TranslateAll(ShapedQueryExpression source, LambdaExpression predicate)
{
Check.NotNull(source, nameof(source));
Check.NotNull(predicate, nameof(predicate));
@@ -215,15 +215,16 @@ protected override ShapedQueryExpression TranslateAll(ShapedQueryExpression sour
}
///
- protected override ShapedQueryExpression TranslateAny(ShapedQueryExpression source, LambdaExpression predicate)
+ protected override ShapedQueryExpression? TranslateAny(ShapedQueryExpression source, LambdaExpression? predicate)
{
if (predicate != null)
{
- source = TranslateWhere(source, predicate);
- if (source == null)
+ var translatedSource = TranslateWhere(source, predicate);
+ if (translatedSource == null)
{
return null;
}
+ source = translatedSource;
}
var selectExpression = (SelectExpression)source.QueryExpression;
@@ -244,7 +245,7 @@ protected override ShapedQueryExpression TranslateAny(ShapedQueryExpression sour
}
///
- protected override ShapedQueryExpression TranslateAverage(ShapedQueryExpression source, LambdaExpression selector, Type resultType)
+ protected override ShapedQueryExpression? TranslateAverage(ShapedQueryExpression source, LambdaExpression? selector, Type resultType)
{
Check.NotNull(source, nameof(source));
Check.NotNull(resultType, nameof(resultType));
@@ -278,7 +279,7 @@ protected override ShapedQueryExpression TranslateAverage(ShapedQueryExpression
}
///
- protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression source, Type resultType)
+ protected override ShapedQueryExpression? TranslateCast(ShapedQueryExpression source, Type resultType)
{
Check.NotNull(source, nameof(source));
Check.NotNull(resultType, nameof(resultType));
@@ -289,7 +290,7 @@ protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression sou
}
///
- protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2)
+ protected override ShapedQueryExpression? TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
Check.NotNull(source1, nameof(source1));
Check.NotNull(source2, nameof(source2));
@@ -300,7 +301,7 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s
}
///
- protected override ShapedQueryExpression TranslateContains(ShapedQueryExpression source, Expression item)
+ protected override ShapedQueryExpression? TranslateContains(ShapedQueryExpression source, Expression item)
{
Check.NotNull(source, nameof(source));
Check.NotNull(item, nameof(item));
@@ -329,7 +330,7 @@ protected override ShapedQueryExpression TranslateContains(ShapedQueryExpression
}
///
- protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression source, LambdaExpression predicate)
+ protected override ShapedQueryExpression? TranslateCount(ShapedQueryExpression source, LambdaExpression? predicate)
{
Check.NotNull(source, nameof(source));
@@ -338,11 +339,12 @@ protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression so
if (predicate != null)
{
- source = TranslateWhere(source, predicate);
- if (source == null)
+ var translatedSource = TranslateWhere(source, predicate);
+ if (translatedSource == null)
{
return null;
}
+ source = translatedSource;
}
HandleGroupByForAggregate(selectExpression, eraseProjection: true);
@@ -365,7 +367,7 @@ protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression so
}
///
- protected override ShapedQueryExpression TranslateDefaultIfEmpty(ShapedQueryExpression source, Expression defaultValue)
+ protected override ShapedQueryExpression? TranslateDefaultIfEmpty(ShapedQueryExpression source, Expression? defaultValue)
{
Check.NotNull(source, nameof(source));
@@ -379,7 +381,7 @@ protected override ShapedQueryExpression TranslateDefaultIfEmpty(ShapedQueryExpr
}
///
- protected override ShapedQueryExpression TranslateDistinct(ShapedQueryExpression source)
+ protected override ShapedQueryExpression? TranslateDistinct(ShapedQueryExpression source)
{
Check.NotNull(source, nameof(source));
@@ -389,7 +391,7 @@ protected override ShapedQueryExpression TranslateDistinct(ShapedQueryExpression
}
///
- protected override ShapedQueryExpression TranslateElementAtOrDefault(
+ protected override ShapedQueryExpression? TranslateElementAtOrDefault(
ShapedQueryExpression source,
Expression index,
bool returnDefault)
@@ -401,7 +403,7 @@ protected override ShapedQueryExpression TranslateElementAtOrDefault(
}
///
- protected override ShapedQueryExpression TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2)
+ protected override ShapedQueryExpression? TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
Check.NotNull(source1, nameof(source1));
Check.NotNull(source2, nameof(source2));
@@ -411,9 +413,9 @@ protected override ShapedQueryExpression TranslateExcept(ShapedQueryExpression s
}
///
- protected override ShapedQueryExpression TranslateFirstOrDefault(
+ protected override ShapedQueryExpression? TranslateFirstOrDefault(
ShapedQueryExpression source,
- LambdaExpression predicate,
+ LambdaExpression? predicate,
Type returnType,
bool returnDefault)
{
@@ -422,11 +424,12 @@ protected override ShapedQueryExpression TranslateFirstOrDefault(
if (predicate != null)
{
- source = TranslateWhere(source, predicate);
- if (source == null)
+ var translatedSource = TranslateWhere(source, predicate);
+ if (translatedSource == null)
{
return null;
}
+ source = translatedSource;
}
var selectExpression = (SelectExpression)source.QueryExpression;
@@ -436,7 +439,7 @@ protected override ShapedQueryExpression TranslateFirstOrDefault(
_queryCompilationContext.Logger.FirstWithoutOrderByAndFilterWarning();
}
- selectExpression.ApplyLimit(TranslateExpression(Expression.Constant(1)));
+ selectExpression.ApplyLimit(TranslateExpression(Expression.Constant(1))!);
return source.ShaperExpression.Type != returnType
? source.UpdateShaperExpression(Expression.Convert(source.ShaperExpression, returnType))
@@ -444,11 +447,11 @@ protected override ShapedQueryExpression TranslateFirstOrDefault(
}
///
- protected override ShapedQueryExpression TranslateGroupBy(
+ protected override ShapedQueryExpression? TranslateGroupBy(
ShapedQueryExpression source,
LambdaExpression keySelector,
- LambdaExpression elementSelector,
- LambdaExpression resultSelector)
+ LambdaExpression? elementSelector,
+ LambdaExpression? resultSelector)
{
Check.NotNull(source, nameof(source));
Check.NotNull(keySelector, nameof(keySelector));
@@ -491,7 +494,7 @@ protected override ShapedQueryExpression TranslateGroupBy(
return null;
}
- private Expression TranslateGroupingKey(Expression expression)
+ private Expression? TranslateGroupingKey(Expression expression)
{
switch (expression)
{
@@ -501,7 +504,7 @@ private Expression TranslateGroupingKey(Expression expression)
return newExpression;
}
- var newArguments = new Expression[newExpression.Arguments.Count];
+ var newArguments = new Expression?[newExpression.Arguments.Count];
for (var i = 0; i < newArguments.Length; i++)
{
newArguments[i] = TranslateGroupingKey(newExpression.Arguments[i]);
@@ -514,7 +517,7 @@ private Expression TranslateGroupingKey(Expression expression)
return newExpression.Update(newArguments);
case MemberInitExpression memberInitExpression:
- var updatedNewExpression = (NewExpression)TranslateGroupingKey(memberInitExpression.NewExpression);
+ var updatedNewExpression = (NewExpression?)TranslateGroupingKey(memberInitExpression.NewExpression);
if (updatedNewExpression == null)
{
return null;
@@ -549,7 +552,7 @@ private Expression TranslateGroupingKey(Expression expression)
}
///
- protected override ShapedQueryExpression TranslateGroupJoin(
+ protected override ShapedQueryExpression? TranslateGroupJoin(
ShapedQueryExpression outer,
ShapedQueryExpression inner,
LambdaExpression outerKeySelector,
@@ -566,7 +569,7 @@ protected override ShapedQueryExpression TranslateGroupJoin(
}
///
- protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2)
+ protected override ShapedQueryExpression? TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
Check.NotNull(source1, nameof(source1));
Check.NotNull(source2, nameof(source2));
@@ -577,7 +580,7 @@ protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpressio
}
///
- protected override ShapedQueryExpression TranslateJoin(
+ protected override ShapedQueryExpression? TranslateJoin(
ShapedQueryExpression outer,
ShapedQueryExpression inner,
LambdaExpression outerKeySelector,
@@ -604,7 +607,7 @@ protected override ShapedQueryExpression TranslateJoin(
}
///
- protected override ShapedQueryExpression TranslateLeftJoin(
+ protected override ShapedQueryExpression? TranslateLeftJoin(
ShapedQueryExpression outer,
ShapedQueryExpression inner,
LambdaExpression outerKeySelector,
@@ -639,11 +642,12 @@ private SqlExpression CreateJoinPredicate(
var outerKey = RemapLambdaBody(outer, outerKeySelector);
var innerKey = RemapLambdaBody(inner, innerKeySelector);
- if (outerKey is NewExpression outerNew)
+ if (outerKey is NewExpression outerNew
+ && outerNew.Arguments.Count > 0)
{
var innerNew = (NewExpression)innerKey;
- SqlExpression result = null;
+ SqlExpression? result = null;
for (var i = 0; i < outerNew.Arguments.Count; i++)
{
var joinPredicate = CreateJoinPredicate(outerNew.Arguments[i], innerNew.Arguments[i]);
@@ -655,23 +659,23 @@ private SqlExpression CreateJoinPredicate(
if (outerNew.Arguments.Count == 1)
{
result = _sqlExpressionFactory.AndAlso(
- result,
+ result!,
CreateJoinPredicate(Expression.Constant(true), Expression.Constant(true)));
}
- return result;
+ return result!;
}
return CreateJoinPredicate(outerKey, innerKey);
}
private SqlExpression CreateJoinPredicate(Expression outerKey, Expression innerKey)
- => TranslateExpression(Expression.Equal(outerKey, innerKey));
+ => TranslateExpression(Expression.Equal(outerKey, innerKey))!;
///
- protected override ShapedQueryExpression TranslateLastOrDefault(
+ protected override ShapedQueryExpression? TranslateLastOrDefault(
ShapedQueryExpression source,
- LambdaExpression predicate,
+ LambdaExpression? predicate,
Type returnType,
bool returnDefault)
{
@@ -687,15 +691,16 @@ protected override ShapedQueryExpression TranslateLastOrDefault(
if (predicate != null)
{
- source = TranslateWhere(source, predicate);
- if (source == null)
+ var translatedSource = TranslateWhere(source, predicate);
+ if (translatedSource == null)
{
return null;
}
+ source = translatedSource;
}
selectExpression.ReverseOrderings();
- selectExpression.ApplyLimit(TranslateExpression(Expression.Constant(1)));
+ selectExpression.ApplyLimit(TranslateExpression(Expression.Constant(1))!);
return source.ShaperExpression.Type != returnType
? source.UpdateShaperExpression(Expression.Convert(source.ShaperExpression, returnType))
@@ -703,7 +708,7 @@ protected override ShapedQueryExpression TranslateLastOrDefault(
}
///
- protected override ShapedQueryExpression TranslateLongCount(ShapedQueryExpression source, LambdaExpression predicate)
+ protected override ShapedQueryExpression? TranslateLongCount(ShapedQueryExpression source, LambdaExpression? predicate)
{
Check.NotNull(source, nameof(source));
@@ -712,11 +717,12 @@ protected override ShapedQueryExpression TranslateLongCount(ShapedQueryExpressio
if (predicate != null)
{
- source = TranslateWhere(source, predicate);
- if (source == null)
+ var translatedSource = TranslateWhere(source, predicate);
+ if (translatedSource == null)
{
return null;
}
+ source = translatedSource;
}
HandleGroupByForAggregate(selectExpression, eraseProjection: true);
@@ -739,7 +745,7 @@ protected override ShapedQueryExpression TranslateLongCount(ShapedQueryExpressio
}
///
- protected override ShapedQueryExpression TranslateMax(ShapedQueryExpression source, LambdaExpression selector, Type resultType)
+ protected override ShapedQueryExpression? TranslateMax(ShapedQueryExpression source, LambdaExpression? selector, Type resultType)
{
Check.NotNull(source, nameof(source));
@@ -771,7 +777,7 @@ protected override ShapedQueryExpression TranslateMax(ShapedQueryExpression sour
}
///
- protected override ShapedQueryExpression TranslateMin(ShapedQueryExpression source, LambdaExpression selector, Type resultType)
+ protected override ShapedQueryExpression? TranslateMin(ShapedQueryExpression source, LambdaExpression? selector, Type resultType)
{
Check.NotNull(source, nameof(source));
@@ -803,7 +809,7 @@ protected override ShapedQueryExpression TranslateMin(ShapedQueryExpression sour
}
///
- protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression source, Type resultType)
+ protected override ShapedQueryExpression? TranslateOfType(ShapedQueryExpression source, Type resultType)
{
Check.NotNull(source, nameof(source));
Check.NotNull(resultType, nameof(resultType));
@@ -859,7 +865,7 @@ protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression s
}
///
- protected override ShapedQueryExpression TranslateOrderBy(
+ protected override ShapedQueryExpression? TranslateOrderBy(
ShapedQueryExpression source,
LambdaExpression keySelector,
bool ascending)
@@ -879,7 +885,7 @@ protected override ShapedQueryExpression TranslateOrderBy(
}
///
- protected override ShapedQueryExpression TranslateReverse(ShapedQueryExpression source)
+ protected override ShapedQueryExpression? TranslateReverse(ShapedQueryExpression source)
{
Check.NotNull(source, nameof(source));
@@ -919,7 +925,7 @@ protected override ShapedQueryExpression TranslateSelect(ShapedQueryExpression s
}
///
- protected override ShapedQueryExpression TranslateSelectMany(
+ protected override ShapedQueryExpression? TranslateSelectMany(
ShapedQueryExpression source,
LambdaExpression collectionSelector,
LambdaExpression resultSelector)
@@ -949,11 +955,12 @@ protected override ShapedQueryExpression TranslateSelectMany(
{
if (defaultIfEmpty)
{
- inner = TranslateDefaultIfEmpty(inner, null);
- if (inner == null)
+ var translatedInner = TranslateDefaultIfEmpty(inner, null);
+ if (translatedInner == null)
{
return null;
}
+ inner = translatedInner;
}
var innerSelectExpression = (SelectExpression)source.QueryExpression;
@@ -968,7 +975,7 @@ protected override ShapedQueryExpression TranslateSelectMany(
private sealed class CorrelationFindingExpressionVisitor : ExpressionVisitor
{
- private ParameterExpression _outerParameter;
+ private ParameterExpression? _outerParameter;
private bool _correlated;
private bool _defaultIfEmpty;
@@ -1014,7 +1021,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
}
///
- protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpression source, LambdaExpression selector)
+ protected override ShapedQueryExpression? TranslateSelectMany(ShapedQueryExpression source, LambdaExpression selector)
{
Check.NotNull(source, nameof(source));
Check.NotNull(selector, nameof(selector));
@@ -1027,9 +1034,9 @@ protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpressi
}
///
- protected override ShapedQueryExpression TranslateSingleOrDefault(
+ protected override ShapedQueryExpression? TranslateSingleOrDefault(
ShapedQueryExpression source,
- LambdaExpression predicate,
+ LambdaExpression? predicate,
Type returnType,
bool returnDefault)
{
@@ -1038,15 +1045,16 @@ protected override ShapedQueryExpression TranslateSingleOrDefault(
if (predicate != null)
{
- source = TranslateWhere(source, predicate);
- if (source == null)
+ var translatedSource = TranslateWhere(source, predicate);
+ if (translatedSource == null)
{
return null;
}
+ source = translatedSource;
}
var selectExpression = (SelectExpression)source.QueryExpression;
- selectExpression.ApplyLimit(TranslateExpression(Expression.Constant(_subquery ? 1 : 2)));
+ selectExpression.ApplyLimit(TranslateExpression(Expression.Constant(_subquery ? 1 : 2))!);
return source.ShaperExpression.Type != returnType
? source.UpdateShaperExpression(Expression.Convert(source.ShaperExpression, returnType))
@@ -1054,7 +1062,7 @@ protected override ShapedQueryExpression TranslateSingleOrDefault(
}
///
- protected override ShapedQueryExpression TranslateSkip(ShapedQueryExpression source, Expression count)
+ protected override ShapedQueryExpression? TranslateSkip(ShapedQueryExpression source, Expression count)
{
Check.NotNull(source, nameof(source));
Check.NotNull(count, nameof(count));
@@ -1077,7 +1085,7 @@ protected override ShapedQueryExpression TranslateSkip(ShapedQueryExpression sou
}
///
- protected override ShapedQueryExpression TranslateSkipWhile(ShapedQueryExpression source, LambdaExpression predicate)
+ protected override ShapedQueryExpression? TranslateSkipWhile(ShapedQueryExpression source, LambdaExpression predicate)
{
Check.NotNull(source, nameof(source));
Check.NotNull(predicate, nameof(predicate));
@@ -1086,7 +1094,7 @@ protected override ShapedQueryExpression TranslateSkipWhile(ShapedQueryExpressio
}
///
- protected override ShapedQueryExpression TranslateSum(ShapedQueryExpression source, LambdaExpression selector, Type resultType)
+ protected override ShapedQueryExpression? TranslateSum(ShapedQueryExpression source, LambdaExpression? selector, Type resultType)
{
Check.NotNull(source, nameof(source));
Check.NotNull(resultType, nameof(resultType));
@@ -1120,7 +1128,7 @@ protected override ShapedQueryExpression TranslateSum(ShapedQueryExpression sour
}
///
- protected override ShapedQueryExpression TranslateTake(ShapedQueryExpression source, Expression count)
+ protected override ShapedQueryExpression? TranslateTake(ShapedQueryExpression source, Expression count)
{
Check.NotNull(source, nameof(source));
Check.NotNull(count, nameof(count));
@@ -1143,7 +1151,7 @@ protected override ShapedQueryExpression TranslateTake(ShapedQueryExpression sou
}
///
- protected override ShapedQueryExpression TranslateTakeWhile(ShapedQueryExpression source, LambdaExpression predicate)
+ protected override ShapedQueryExpression? TranslateTakeWhile(ShapedQueryExpression source, LambdaExpression predicate)
{
Check.NotNull(source, nameof(source));
Check.NotNull(predicate, nameof(predicate));
@@ -1152,7 +1160,7 @@ protected override ShapedQueryExpression TranslateTakeWhile(ShapedQueryExpressio
}
///
- protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending)
+ protected override ShapedQueryExpression? TranslateThenBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending)
{
Check.NotNull(source, nameof(source));
Check.NotNull(keySelector, nameof(keySelector));
@@ -1169,7 +1177,7 @@ protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression s
}
///
- protected override ShapedQueryExpression TranslateUnion(ShapedQueryExpression source1, ShapedQueryExpression source2)
+ protected override ShapedQueryExpression? TranslateUnion(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
Check.NotNull(source1, nameof(source1));
Check.NotNull(source2, nameof(source2));
@@ -1179,7 +1187,7 @@ protected override ShapedQueryExpression TranslateUnion(ShapedQueryExpression so
}
///
- protected override ShapedQueryExpression TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate)
+ protected override ShapedQueryExpression? TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate)
{
Check.NotNull(source, nameof(source));
Check.NotNull(predicate, nameof(predicate));
@@ -1195,7 +1203,7 @@ protected override ShapedQueryExpression TranslateWhere(ShapedQueryExpression so
return source;
}
- private SqlExpression TranslateExpression(Expression expression)
+ private SqlExpression? TranslateExpression(Expression expression)
{
var translation = _sqlTranslator.Translate(expression);
if (translation == null && _sqlTranslator.TranslationErrorDetails != null)
@@ -1206,7 +1214,7 @@ private SqlExpression TranslateExpression(Expression expression)
return translation;
}
- private SqlExpression TranslateLambdaExpression(
+ private SqlExpression? TranslateLambdaExpression(
ShapedQueryExpression shapedQueryExpression,
LambdaExpression lambdaExpression)
=> TranslateExpression(RemapLambdaBody(shapedQueryExpression, lambdaExpression));
@@ -1224,21 +1232,20 @@ internal Expression ExpandWeakEntities(SelectExpression selectExpression, Expres
private sealed class WeakEntityExpandingExpressionVisitor : ExpressionVisitor
{
- private SelectExpression _selectExpression;
private readonly RelationalSqlTranslatingExpressionVisitor _sqlTranslator;
private readonly ISqlExpressionFactory _sqlExpressionFactory;
+ private SelectExpression _selectExpression;
+
public WeakEntityExpandingExpressionVisitor(
RelationalSqlTranslatingExpressionVisitor sqlTranslator,
ISqlExpressionFactory sqlExpressionFactory)
{
_sqlTranslator = sqlTranslator;
_sqlExpressionFactory = sqlExpressionFactory;
+ _selectExpression = null!;
}
- public string TranslationErrorDetails
- => _sqlTranslator.TranslationErrorDetails;
-
public Expression Expand(SelectExpression selectExpression, Expression lambdaBody)
{
_selectExpression = selectExpression;
@@ -1289,7 +1296,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
: base.VisitExtension(extensionExpression);
}
- private Expression TryExpand(Expression source, MemberIdentity member)
+ private Expression? TryExpand(Expression source, MemberIdentity member)
{
source = source.UnwrapTypeConversion(out var convertedType);
if (!(source is EntityShaperExpression entityShaperExpression))
@@ -1371,7 +1378,7 @@ private Expression TryExpand(Expression source, MemberIdentity member)
var entityProjectionExpression = (EntityProjectionExpression)
(entityShaperExpression.ValueBufferExpression is ProjectionBindingExpression projectionBindingExpression
- ? _selectExpression.GetMappedProjection(projectionBindingExpression.ProjectionMember)
+ ? _selectExpression.GetMappedProjection(projectionBindingExpression.ProjectionMember!)
: entityShaperExpression.ValueBufferExpression);
var innerShaper = entityProjectionExpression.BindNavigation(navigation);
@@ -1391,7 +1398,7 @@ private Expression TryExpand(Expression source, MemberIdentity member)
{
// Mapped to same table
// We get identifying column to figure out tableExpression to pull columns from and nullability of most principal side
- var identifyingColumn = entityProjectionExpression.BindProperty(entityType.FindPrimaryKey().Properties.First());
+ var identifyingColumn = entityProjectionExpression.BindProperty(entityType.FindPrimaryKey()!.Properties.First());
var principalNullable = identifyingColumn.IsNullable
// Also make nullable if navigation is on derived type and and principal is TPT
// Since identifying PK would be non-nullable but principal can still be null
@@ -1435,7 +1442,7 @@ private Expression TryExpand(Expression source, MemberIdentity member)
: foreignKey.Properties,
makeNullable);
- var joinPredicate = _sqlTranslator.Translate(Expression.Equal(outerKey, innerKey));
+ var joinPredicate = _sqlTranslator.Translate(Expression.Equal(outerKey, innerKey))!;
_selectExpression.AddLeftJoin(innerSelectExpression, joinPredicate);
var leftJoinTable = ((LeftJoinExpression)_selectExpression.Tables.Last()).Table;
var propertyExpressions = GetPropertyExpressionsFromJoinedTable(targetEntityType, table, leftJoinTable);
@@ -1450,7 +1457,7 @@ private Expression TryExpand(Expression source, MemberIdentity member)
return innerShaper;
}
- private static IDictionary GetPropertyExpressionFromSameTable(
+ private static IDictionary? GetPropertyExpressionFromSameTable(
IEntityType entityType,
ITableBase table,
SelectExpression selectExpression,
@@ -1566,9 +1573,9 @@ private static void HandleGroupByForAggregate(SelectExpression selectExpression,
}
}
- private ShapedQueryExpression AggregateResultShaper(
+ private ShapedQueryExpression? AggregateResultShaper(
ShapedQueryExpression source,
- Expression projection,
+ Expression? projection,
bool throwWhenEmpty,
Type resultType)
{
diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs
index 4421414aa05..70d5c283dec 100644
--- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs
+++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs
index cce1f452601..41a768e3a29 100644
--- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs
@@ -20,6 +20,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
public partial class RelationalShapedQueryCompilingExpressionVisitor
@@ -84,21 +86,21 @@ private static readonly MethodInfo _collectionAccessorAddMethodInfo
= typeof(IClrCollectionAccessor).GetTypeInfo().GetDeclaredMethod(nameof(IClrCollectionAccessor.Add));
private readonly RelationalShapedQueryCompilingExpressionVisitor _parentVisitor;
- private readonly ISet _tags;
+ private readonly ISet? _tags;
private readonly bool _isTracking;
private readonly bool _isAsync;
private readonly bool _splitQuery;
private readonly bool _detailedErrorsEnabled;
private readonly bool _generateCommandCache;
private readonly ParameterExpression _resultCoordinatorParameter;
- private readonly ParameterExpression _executionStrategyParameter;
+ private readonly ParameterExpression? _executionStrategyParameter;
// States scoped to SelectExpression
private readonly SelectExpression _selectExpression;
private readonly ParameterExpression _dataReaderParameter;
private readonly ParameterExpression _resultContextParameter;
- private readonly ParameterExpression _indexMapParameter;
- private readonly ReaderColumn[] _readerColumns;
+ private readonly ParameterExpression? _indexMapParameter;
+ private readonly ReaderColumn[]? _readerColumns;
// States to materialize only once
private readonly IDictionary _variableShaperMapping = new Dictionary();
@@ -112,9 +114,9 @@ private static readonly MethodInfo _collectionAccessorAddMethodInfo
private readonly List _includeExpressions = new List();
// If there is collection shaper then we need to construct ValuesArray to store values temporarily in ResultContext
- private List _collectionPopulatingExpressions;
- private Expression _valuesArrayExpression;
- private List _valuesArrayInitializers;
+ private List? _collectionPopulatingExpressions;
+ private Expression? _valuesArrayExpression;
+ private List? _valuesArrayInitializers;
private bool _containsCollectionMaterialization;
@@ -166,7 +168,7 @@ private ShaperProcessingExpressionVisitor(
SelectExpression selectExpression,
ParameterExpression dataReaderParameter,
ParameterExpression resultContextParameter,
- ReaderColumn[] readerColumns)
+ ReaderColumn[]? readerColumns)
{
_parentVisitor = parentVisitor;
_resultCoordinatorParameter = resultCoordinatorParameter;
@@ -214,8 +216,8 @@ private ShaperProcessingExpressionVisitor(
public LambdaExpression ProcessShaper(
Expression shaperExpression,
- out RelationalCommandCache relationalCommandCache,
- out LambdaExpression relatedDataLoaders)
+ out RelationalCommandCache? relationalCommandCache,
+ out LambdaExpression? relatedDataLoaders)
{
relatedDataLoaders = null;
@@ -410,7 +412,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
if (_containsCollectionMaterialization)
{
- _valuesArrayInitializers.Add(entityParameter);
+ _valuesArrayInitializers!.Add(entityParameter);
accessor = Expression.Convert(
Expression.ArrayIndex(
_valuesArrayExpression,
@@ -438,7 +440,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
_dataReaderParameter,
projectionIndex,
IsNullableProjection(projection),
- projection.Expression.TypeMapping,
+ projection.Expression.TypeMapping!,
projectionBindingExpression.Type);
}
@@ -465,7 +467,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
_dataReaderParameter,
projectionIndex,
nullable,
- projection.Expression.TypeMapping,
+ projection.Expression.TypeMapping!,
valueParameter.Type)));
if (_containsCollectionMaterialization)
@@ -476,7 +478,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
expressionToAdd = Expression.Convert(expressionToAdd, typeof(object));
}
- _valuesArrayInitializers.Add(expressionToAdd);
+ _valuesArrayInitializers!.Add(expressionToAdd);
accessor = Expression.Convert(
Expression.ArrayIndex(
_valuesArrayExpression,
@@ -507,7 +509,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
var entityType = entity.Type;
var navigation = includeExpression.Navigation;
- var includingEntityType = navigation.DeclaringEntityType.ClrType;
+ var includingEntityType = navigation.DeclaringEntityType.ClrType!;
if (includingEntityType != entityType
&& includingEntityType.IsAssignableFrom(entityType))
{
@@ -552,7 +554,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
var relatedEntityType = innerShaper.ReturnType;
var inverseNavigation = navigation.Inverse;
- _collectionPopulatingExpressions.Add(
+ _collectionPopulatingExpressions!.Add(
Expression.Call(
_populateIncludeCollectionMethodInfo.MakeGenericMethod(includingEntityType, relatedEntityType),
collectionIdConstant,
@@ -583,7 +585,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
{
var innerProcessor = new ShaperProcessingExpressionVisitor(
_parentVisitor, _resultCoordinatorParameter,
- _executionStrategyParameter, relationalSplitCollectionShaperExpression.SelectExpression, _tags);
+ _executionStrategyParameter!, relationalSplitCollectionShaperExpression.SelectExpression, _tags!);
var innerShaper = innerProcessor.ProcessShaper(
relationalSplitCollectionShaperExpression.InnerShaper,
out var relationalCommandCache,
@@ -591,7 +593,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
var entityType = entity.Type;
var navigation = includeExpression.Navigation;
- var includingEntityType = navigation.DeclaringEntityType.ClrType;
+ var includingEntityType = navigation.DeclaringEntityType.ClrType!;
if (includingEntityType != entityType
&& includingEntityType.IsAssignableFrom(entityType))
{
@@ -634,7 +636,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
var relatedEntityType = innerShaper.ReturnType;
var inverseNavigation = navigation.Inverse;
- _collectionPopulatingExpressions.Add(
+ _collectionPopulatingExpressions!.Add(
Expression.Call(
(_isAsync ? _populateSplitIncludeCollectionAsyncMethodInfo : _populateSplitIncludeCollectionMethodInfo)
.MakeGenericMethod(includingEntityType, relatedEntityType),
@@ -665,9 +667,9 @@ protected override Expression VisitExtension(Expression extensionExpression)
var navigationExpression = Visit(includeExpression.NavigationExpression);
var entityType = entity.Type;
var navigation = includeExpression.Navigation;
- var includingType = navigation.DeclaringEntityType.ClrType;
+ var includingType = navigation.DeclaringEntityType.ClrType!;
var inverseNavigation = navigation.Inverse;
- var relatedEntityType = navigation.TargetEntityType.ClrType;
+ var relatedEntityType = navigation.TargetEntityType.ClrType!;
if (includingType != entityType
&& includingType.IsAssignableFrom(entityType))
{
@@ -745,14 +747,14 @@ protected override Expression VisitExtension(Expression extensionExpression)
Expression.Constant(outerIdentifierLambda.Compile()),
Expression.Constant(collectionAccessor, typeof(IClrCollectionAccessor)))));
- _valuesArrayInitializers.Add(collectionParameter);
+ _valuesArrayInitializers!.Add(collectionParameter);
accessor = Expression.Convert(
Expression.ArrayIndex(
_valuesArrayExpression,
Expression.Constant(_valuesArrayInitializers.Count - 1)),
relationalCollectionShaperExpression.Type);
- _collectionPopulatingExpressions.Add(
+ _collectionPopulatingExpressions!.Add(
Expression.Call(
_populateCollectionMethodInfo.MakeGenericMethod(collectionType, elementType, relatedElementType),
collectionIdConstant,
@@ -786,7 +788,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
{
var innerProcessor = new ShaperProcessingExpressionVisitor(
_parentVisitor, _resultCoordinatorParameter,
- _executionStrategyParameter, relationalSplitCollectionShaperExpression.SelectExpression, _tags);
+ _executionStrategyParameter!, relationalSplitCollectionShaperExpression.SelectExpression, _tags!);
var innerShaper = innerProcessor.ProcessShaper(
relationalSplitCollectionShaperExpression.InnerShaper,
out var relationalCommandCache,
@@ -832,14 +834,14 @@ protected override Expression VisitExtension(Expression extensionExpression)
Expression.Constant(parentIdentifierLambda.Compile()),
Expression.Constant(collectionAccessor, typeof(IClrCollectionAccessor)))));
- _valuesArrayInitializers.Add(collectionParameter);
+ _valuesArrayInitializers!.Add(collectionParameter);
accessor = Expression.Convert(
Expression.ArrayIndex(
_valuesArrayExpression,
Expression.Constant(_valuesArrayInitializers.Count - 1)),
relationalSplitCollectionShaperExpression.Type);
- _collectionPopulatingExpressions.Add(
+ _collectionPopulatingExpressions!.Add(
Expression.Call(
(_isAsync ? _populateSplitCollectionAsyncMethodInfo : _populateSplitCollectionMethodInfo)
.MakeGenericMethod(collectionType, elementType, relatedElementType),
@@ -899,7 +901,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
_dataReaderParameter,
projectionIndex,
nullable,
- projection.Expression.TypeMapping,
+ projection.Expression.TypeMapping!,
methodCallExpression.Type,
property);
}
@@ -961,7 +963,7 @@ private object GetProjectionIndex(ProjectionBindingExpression projectionBindingE
? ((ConstantExpression)_selectExpression.GetMappedProjection(projectionBindingExpression.ProjectionMember)).Value
: (projectionBindingExpression.Index != null
? (object)projectionBindingExpression.Index
- : projectionBindingExpression.IndexMap);
+ : projectionBindingExpression.IndexMap)!;
private static bool IsNullableProjection(ProjectionExpression projection)
=> !(projection.Expression is ColumnExpression column) || column.IsNullable;
@@ -972,7 +974,7 @@ private Expression CreateGetValueExpression(
bool nullable,
RelationalTypeMapping typeMapping,
Type type,
- IPropertyBase property = null)
+ IPropertyBase? property = null)
{
Check.DebugAssert(
property != null || type.IsNullableType(), "Must read nullable value from database if property is not specified.");
@@ -1079,7 +1081,7 @@ private static TValue ThrowReadValueException(
Exception exception,
object value,
Type expectedType,
- IPropertyBase property = null)
+ IPropertyBase? property = null)
{
var actualType = value?.GetType();
@@ -1167,7 +1169,7 @@ private static void InitializeIncludeCollection(
where TParent : class
where TNavigationEntity : class, TParent
{
- object collection = null;
+ object? collection = null;
if (entity is TNavigationEntity)
{
if (trackingQuery)
@@ -1208,7 +1210,7 @@ private static void PopulateIncludeCollection
where TIncludingEntity : class
where TIncludedEntity : class
{
- var collectionMaterializationContext = resultCoordinator.Collections[collectionId];
+ var collectionMaterializationContext = resultCoordinator.Collections[collectionId]!;
if (collectionMaterializationContext.Parent is TIncludingEntity entity)
{
if (resultCoordinator.HasNext == false)
@@ -1321,7 +1323,7 @@ private static void InitializeSplitIncludeCollection
where TParent : class
where TNavigationEntity : class, TParent
{
- object collection = null;
+ object? collection = null;
if (entity is TNavigationEntity)
{
if (trackingQuery)
@@ -1364,7 +1366,7 @@ private static void PopulateSplitIncludeCollection InitializeReaderAsync(DbContext _, bool result, CancellationTok
return result;
}
- resultCoordinator.SetDataReader(collectionId, dataReader);
+ resultCoordinator.SetDataReader(collectionId, dataReader!);
}
- var splitQueryCollectionContext = resultCoordinator.Collections[collectionId];
- var dataReaderContext = resultCoordinator.DataReaders[collectionId];
+ var splitQueryCollectionContext = resultCoordinator.Collections[collectionId]!;
+ var dataReaderContext = resultCoordinator.DataReaders[collectionId]!;
var dbDataReader = dataReaderContext.DataReader.DbDataReader;
if (splitQueryCollectionContext.Parent is TIncludingEntity entity)
{
@@ -1549,7 +1551,7 @@ private static void PopulateCollection(
where TRelatedEntity : TElement
where TCollection : class, ICollection
{
- var collectionMaterializationContext = resultCoordinator.Collections[collectionId];
+ var collectionMaterializationContext = resultCoordinator.Collections[collectionId]!;
if (collectionMaterializationContext.Collection is null)
{
// nothing to materialize since no collection created
@@ -1683,7 +1685,7 @@ private static void PopulateSplitCollection InitializeReaderAsync(DbContext _, bool result, CancellationTok
return result;
}
- resultCoordinator.SetDataReader(collectionId, dataReader);
+ resultCoordinator.SetDataReader(collectionId, dataReader!);
}
- var splitQueryCollectionContext = resultCoordinator.Collections[collectionId];
- var dataReaderContext = resultCoordinator.DataReaders[collectionId];
+ var splitQueryCollectionContext = resultCoordinator.Collections[collectionId]!;
+ var dataReaderContext = resultCoordinator.DataReaders[collectionId]!;
var dbDataReader = dataReaderContext.DataReader.DbDataReader;
if (splitQueryCollectionContext.Collection is null)
{
diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.cs
index 4dcceb1e99f..264d5522a11 100644
--- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.cs
@@ -13,6 +13,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs
index c755b1257ac..a8ac8c8f2b3 100644
--- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs
+++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/RelationalSplitCollectionShaperExpression.cs b/src/EFCore.Relational/Query/RelationalSplitCollectionShaperExpression.cs
index a84fd796c34..e3f0b9a9088 100644
--- a/src/EFCore.Relational/Query/RelationalSplitCollectionShaperExpression.cs
+++ b/src/EFCore.Relational/Query/RelationalSplitCollectionShaperExpression.cs
@@ -10,6 +10,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
@@ -42,7 +44,7 @@ public RelationalSplitCollectionShaperExpression(
[NotNull] IReadOnlyList identifierValueComparers,
[NotNull] SelectExpression selectExpression,
[NotNull] Expression innerShaper,
- [CanBeNull] INavigationBase navigation,
+ [CanBeNull] INavigationBase? navigation,
[NotNull] Type elementType)
{
Check.NotNull(parentIdentifier, nameof(parentIdentifier));
@@ -94,7 +96,7 @@ public RelationalSplitCollectionShaperExpression(
///
/// The navigation if associated with the collection.
///
- public virtual INavigationBase Navigation { get; }
+ public virtual INavigationBase? Navigation { get; }
///
/// The clr type of elements of the collection.
diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs
index 9d1b2c652ca..fb8584c9f7f 100644
--- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs
@@ -15,6 +15,9 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+using CA = System.Diagnostics.CodeAnalysis;
+
+#nullable enable
namespace Microsoft.EntityFrameworkCore.Query
{
@@ -78,7 +81,7 @@ public RelationalSqlTranslatingExpressionVisitor(
///
/// Detailed information about errors encountered during translation.
///
- public virtual string TranslationErrorDetails { get; private set; }
+ public virtual string? TranslationErrorDetails { get; private set; }
///
/// Adds detailed information about error encountered during translation.
@@ -108,7 +111,7 @@ protected virtual void AddTranslationErrorDetails([NotNull] string details)
///
/// An expression to translate.
/// A SQL translation of the given expression.
- public virtual SqlExpression Translate([NotNull] Expression expression)
+ public virtual SqlExpression? Translate([NotNull] Expression expression)
{
Check.NotNull(expression, nameof(expression));
@@ -117,7 +120,7 @@ public virtual SqlExpression Translate([NotNull] Expression expression)
return TranslateInternal(expression);
}
- private SqlExpression TranslateInternal(Expression expression)
+ private SqlExpression? TranslateInternal(Expression expression)
{
var result = Visit(expression);
@@ -151,7 +154,7 @@ private SqlExpression TranslateInternal(Expression expression)
///
/// An expression to translate Average over.
/// A SQL translation of Average over the given expression.
- public virtual SqlExpression TranslateAverage([NotNull] SqlExpression sqlExpression)
+ public virtual SqlExpression? TranslateAverage([NotNull] SqlExpression sqlExpression)
{
Check.NotNull(sqlExpression, nameof(sqlExpression));
@@ -191,7 +194,7 @@ public virtual SqlExpression TranslateAverage([NotNull] SqlExpression sqlExpress
///
/// An expression to translate Count over.
/// A SQL translation of Count over the given expression.
- public virtual SqlExpression TranslateCount([NotNull] SqlExpression sqlExpression)
+ public virtual SqlExpression? TranslateCount([NotNull] SqlExpression sqlExpression)
{
Check.NotNull(sqlExpression, nameof(sqlExpression));
@@ -209,7 +212,7 @@ public virtual SqlExpression TranslateCount([NotNull] SqlExpression sqlExpressio
///
/// An expression to translate LongCount over.
/// A SQL translation of LongCount over the given expression.
- public virtual SqlExpression TranslateLongCount([NotNull] SqlExpression sqlExpression)
+ public virtual SqlExpression? TranslateLongCount([NotNull] SqlExpression sqlExpression)
{
Check.NotNull(sqlExpression, nameof(sqlExpression));
@@ -227,7 +230,7 @@ public virtual SqlExpression TranslateLongCount([NotNull] SqlExpression sqlExpre
///
/// An expression to translate Max over.
/// A SQL translation of Max over the given expression.
- public virtual SqlExpression TranslateMax([NotNull] SqlExpression sqlExpression)
+ public virtual SqlExpression? TranslateMax([NotNull] SqlExpression sqlExpression)
{
Check.NotNull(sqlExpression, nameof(sqlExpression));
@@ -247,7 +250,7 @@ public virtual SqlExpression TranslateMax([NotNull] SqlExpression sqlExpression)
///
/// An expression to translate Min over.
/// A SQL translation of Min over the given expression.
- public virtual SqlExpression TranslateMin([NotNull] SqlExpression sqlExpression)
+ public virtual SqlExpression? TranslateMin([NotNull] SqlExpression sqlExpression)
{
Check.NotNull(sqlExpression, nameof(sqlExpression));
@@ -267,7 +270,7 @@ public virtual SqlExpression TranslateMin([NotNull] SqlExpression sqlExpression)
///
/// An expression to translate Sum over.
/// A SQL translation of Sum over the given expression.
- public virtual SqlExpression TranslateSum([NotNull] SqlExpression sqlExpression)
+ public virtual SqlExpression? TranslateSum([NotNull] SqlExpression sqlExpression)
{
Check.NotNull(sqlExpression, nameof(sqlExpression));
@@ -293,7 +296,7 @@ public virtual SqlExpression TranslateSum([NotNull] SqlExpression sqlExpression)
}
///
- protected override Expression VisitBinary(BinaryExpression binaryExpression)
+ protected override Expression? VisitBinary(BinaryExpression binaryExpression)
{
Check.NotNull(binaryExpression, nameof(binaryExpression));
@@ -331,7 +334,7 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
|| binaryExpression.NodeType == ExpressionType.NotEqual)
// Visited expression could be null, We need to pass MemberInitExpression
&& TryRewriteEntityEquality(
- binaryExpression.NodeType, visitedLeft ?? left, visitedRight ?? right, equalsMethod: false, out var result))
+ binaryExpression.NodeType, visitedLeft ?? left!, visitedRight ?? right!, equalsMethod: false, out var result))
{
return result;
}
@@ -348,14 +351,14 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
|| TranslationFailed(binaryExpression.Right, visitedRight, out var sqlRight)
? null
: uncheckedNodeTypeVariant == ExpressionType.Coalesce
- ? _sqlExpressionFactory.Coalesce(sqlLeft, sqlRight)
- : (Expression)_sqlExpressionFactory.MakeBinary(
+ ? _sqlExpressionFactory.Coalesce(sqlLeft!, sqlRight!)
+ : (Expression?)_sqlExpressionFactory.MakeBinary(
uncheckedNodeTypeVariant,
- sqlLeft,
- sqlRight,
+ sqlLeft!,
+ sqlRight!,
null);
- static bool TryUnwrapConvertToObject(Expression expression, out Expression operand)
+ static bool TryUnwrapConvertToObject(Expression expression, out Expression? operand)
{
if (expression is UnaryExpression convertExpression
&& (convertExpression.NodeType == ExpressionType.Convert
@@ -372,7 +375,7 @@ static bool TryUnwrapConvertToObject(Expression expression, out Expression opera
}
///
- protected override Expression VisitConditional(ConditionalExpression conditionalExpression)
+ protected override Expression? VisitConditional(ConditionalExpression conditionalExpression)
{
Check.NotNull(conditionalExpression, nameof(conditionalExpression));
@@ -384,15 +387,15 @@ protected override Expression VisitConditional(ConditionalExpression conditional
|| TranslationFailed(conditionalExpression.IfTrue, ifTrue, out var sqlIfTrue)
|| TranslationFailed(conditionalExpression.IfFalse, ifFalse, out var sqlIfFalse)
? null
- : _sqlExpressionFactory.Case(new[] { new CaseWhenClause(sqlTest, sqlIfTrue) }, sqlIfFalse);
+ : _sqlExpressionFactory.Case(new[] { new CaseWhenClause(sqlTest!, sqlIfTrue!) }, sqlIfFalse);
}
///
- protected override Expression VisitConstant(ConstantExpression constantExpression)
+ protected override Expression? VisitConstant(ConstantExpression constantExpression)
=> new SqlConstantExpression(Check.NotNull(constantExpression, nameof(constantExpression)), null);
///
- protected override Expression VisitExtension(Expression extensionExpression)
+ protected override Expression? VisitExtension(Expression extensionExpression)
{
Check.NotNull(extensionExpression, nameof(extensionExpression));
@@ -421,19 +424,19 @@ protected override Expression VisitExtension(Expression extensionExpression)
}
///
- protected override Expression VisitInvocation(InvocationExpression invocationExpression)
+ protected override Expression? VisitInvocation(InvocationExpression invocationExpression)
=> null;
///
- protected override Expression VisitLambda(Expression lambdaExpression)
+ protected override Expression? VisitLambda(Expression lambdaExpression)
=> null;
///
- protected override Expression VisitListInit(ListInitExpression listInitExpression)
+ protected override Expression? VisitListInit(ListInitExpression listInitExpression)
=> null;
///
- protected override Expression VisitMember(MemberExpression memberExpression)
+ protected override Expression? VisitMember(MemberExpression memberExpression)
{
Check.NotNull(memberExpression, nameof(memberExpression));
@@ -447,11 +450,11 @@ protected override Expression VisitMember(MemberExpression memberExpression)
}
///
- protected override Expression VisitMemberInit(MemberInitExpression memberInitExpression)
+ protected override Expression? VisitMemberInit(MemberInitExpression memberInitExpression)
=> GetConstantOrNull(Check.NotNull(memberInitExpression, nameof(memberInitExpression)));
///
- protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)
+ protected override Expression? VisitMethodCall(MethodCallExpression methodCallExpression)
{
Check.NotNull(methodCallExpression, nameof(methodCallExpression));
@@ -476,7 +479,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
if (methodCallExpression.Arguments[0].Type.TryGetElementType(typeof(IQueryable<>)) == null
&& Visit(methodCallExpression.Arguments[0]) is GroupingElementExpression groupingElementExpression)
{
- Expression result;
+ Expression? result;
switch (methodCallExpression.Method.Name)
{
case nameof(Enumerable.Average):
@@ -494,16 +497,17 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
case nameof(Enumerable.Count):
if (methodCallExpression.Arguments.Count == 2)
{
- groupingElementExpression = ApplyPredicate(
+ var newGroupingElementExpression = ApplyPredicate(
groupingElementExpression, methodCallExpression.Arguments[1].UnwrapLambdaFromQuote());
- if (groupingElementExpression == null)
+ if (newGroupingElementExpression == null)
{
result = null;
break;
}
+ groupingElementExpression = newGroupingElementExpression;
}
- result = TranslateCount(GetExpressionForAggregation(groupingElementExpression, starProjection: true));
+ result = TranslateCount(GetExpressionForAggregation(groupingElementExpression, starProjection: true)!);
break;
case nameof(Enumerable.Distinct):
@@ -517,16 +521,17 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
case nameof(Enumerable.LongCount):
if (methodCallExpression.Arguments.Count == 2)
{
- groupingElementExpression = ApplyPredicate(
+ var newGroupingElementExpression = ApplyPredicate(
groupingElementExpression, methodCallExpression.Arguments[1].UnwrapLambdaFromQuote());
- if (groupingElementExpression == null)
+ if (newGroupingElementExpression == null)
{
result = null;
break;
}
+ groupingElementExpression = newGroupingElementExpression;
}
- result = TranslateLongCount(GetExpressionForAggregation(groupingElementExpression, starProjection: true));
+ result = TranslateLongCount(GetExpressionForAggregation(groupingElementExpression, starProjection: true)!);
break;
case nameof(Enumerable.Max):
@@ -580,7 +585,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
return result ?? throw new InvalidOperationException(CoreStrings.TranslationFailed(methodCallExpression.Print()));
- GroupingElementExpression ApplyPredicate(GroupingElementExpression groupingElement, LambdaExpression lambdaExpression)
+ GroupingElementExpression? ApplyPredicate(GroupingElementExpression groupingElement, LambdaExpression lambdaExpression)
{
var predicate = TranslateInternal(RemapLambda(groupingElement, lambdaExpression));
@@ -602,7 +607,7 @@ static Expression RemapLambda(GroupingElementExpression groupingElement, LambdaE
=> ReplacingExpressionVisitor.Replace(
lambdaExpression.Parameters[0], groupingElement.Element, lambdaExpression.Body);
- SqlExpression GetExpressionForAggregation(GroupingElementExpression groupingElement, bool starProjection = false)
+ SqlExpression? GetExpressionForAggregation(GroupingElementExpression groupingElement, bool starProjection = false)
{
var selector = TranslateInternal(groupingElement.Element);
if (selector == null)
@@ -668,7 +673,7 @@ static bool IsAggregateResultWithCustomShaper(MethodInfo method)
var shaperExpression = subqueryTranslation.ShaperExpression;
var innerExpression = shaperExpression;
- Type convertedType = null;
+ Type? convertedType = null;
if (shaperExpression is UnaryExpression unaryExpression
&& unaryExpression.NodeType == ExpressionType.Convert)
{
@@ -720,7 +725,7 @@ static bool IsAggregateResultWithCustomShaper(MethodInfo method)
return scalarSubqueryExpression;
}
- SqlExpression sqlObject = null;
+ SqlExpression? sqlObject = null;
SqlExpression[] arguments;
var method = methodCallExpression.Method;
@@ -846,7 +851,7 @@ static bool IsAggregateResultWithCustomShaper(MethodInfo method)
return null;
}
- arguments[i] = sqlArgument;
+ arguments[i] = sqlArgument!;
}
}
@@ -873,21 +878,21 @@ static bool IsAggregateResultWithCustomShaper(MethodInfo method)
}
///
- protected override Expression VisitNew(NewExpression newExpression)
+ protected override Expression? VisitNew(NewExpression newExpression)
=> GetConstantOrNull(Check.NotNull(newExpression, nameof(newExpression)));
///
- protected override Expression VisitNewArray(NewArrayExpression newArrayExpression)
+ protected override Expression? VisitNewArray(NewArrayExpression newArrayExpression)
=> null;
///
- protected override Expression VisitParameter(ParameterExpression parameterExpression)
+ protected override Expression? VisitParameter(ParameterExpression parameterExpression)
=> parameterExpression.Name?.StartsWith(QueryCompilationContext.QueryParameterPrefix, StringComparison.Ordinal) == true
? new SqlParameterExpression(Check.NotNull(parameterExpression, nameof(parameterExpression)), null)
: null;
///
- protected override Expression VisitTypeBinary(TypeBinaryExpression typeBinaryExpression)
+ protected override Expression? VisitTypeBinary(TypeBinaryExpression typeBinaryExpression)
{
Check.NotNull(typeBinaryExpression, nameof(typeBinaryExpression));
@@ -953,10 +958,10 @@ SqlExpression GeneratePredicateTPT(EntityProjectionExpression entityProjectionEx
return discriminatorValues.Count == 1
? _sqlExpressionFactory.Equal(
- entityProjectionExpression.DiscriminatorExpression,
+ entityProjectionExpression.DiscriminatorExpression!,
_sqlExpressionFactory.Constant(discriminatorValues[0]))
: (SqlExpression)_sqlExpressionFactory.In(
- entityProjectionExpression.DiscriminatorExpression,
+ entityProjectionExpression.DiscriminatorExpression!,
_sqlExpressionFactory.Constant(discriminatorValues),
negated: false);
}
@@ -997,7 +1002,7 @@ static bool HasSiblings(IEntityType entityType)
}
///
- protected override Expression VisitUnary(UnaryExpression unaryExpression)
+ protected override Expression? VisitUnary(UnaryExpression unaryExpression)
{
Check.NotNull(unaryExpression, nameof(unaryExpression));
@@ -1019,11 +1024,11 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression)
switch (unaryExpression.NodeType)
{
case ExpressionType.Not:
- return _sqlExpressionFactory.Not(sqlOperand);
+ return _sqlExpressionFactory.Not(sqlOperand!);
case ExpressionType.Negate:
case ExpressionType.NegateChecked:
- return _sqlExpressionFactory.Negate(sqlOperand);
+ return _sqlExpressionFactory.Negate(sqlOperand!);
case ExpressionType.Convert:
case ExpressionType.ConvertChecked:
@@ -1043,7 +1048,7 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression)
{
sqlOperand = _sqlExpressionFactory.ApplyDefaultTypeMapping(sqlOperand);
- return _sqlExpressionFactory.Convert(sqlOperand, unaryExpression.Type);
+ return _sqlExpressionFactory.Convert(sqlOperand!, unaryExpression.Type);
}
break;
@@ -1055,7 +1060,7 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression)
return null;
}
- private Expression TryBindMember(Expression source, MemberIdentity member)
+ private Expression? TryBindMember(Expression source, MemberIdentity member)
{
if (!(source is EntityReferenceExpression entityReferenceExpression))
{
@@ -1080,7 +1085,7 @@ private Expression TryBindMember(Expression source, MemberIdentity member)
return null;
}
- private SqlExpression BindProperty(EntityReferenceExpression entityReferenceExpression, IProperty property)
+ private SqlExpression? BindProperty(EntityReferenceExpression entityReferenceExpression, IProperty property)
{
if (entityReferenceExpression.ParameterEntity != null)
{
@@ -1104,7 +1109,7 @@ private SqlExpression BindProperty(EntityReferenceExpression entityReferenceExpr
else
{
// This has to be index map since entities cannot map to just integer index
- var index = projectionBindingExpression.IndexMap[property];
+ var index = projectionBindingExpression.IndexMap![property];
innerProjection = subSelectExpression.Projection[index].Expression;
subSelectExpression.ClearProjection();
}
@@ -1164,7 +1169,7 @@ private static Expression ConvertObjectArrayEqualityComparison(Expression left,
.Aggregate((a, b) => Expression.AndAlso(a, b));
}
- private static SqlConstantExpression GetConstantOrNull(Expression expression)
+ private static SqlConstantExpression? GetConstantOrNull(Expression expression)
=> CanEvaluate(expression)
? new SqlConstantExpression(
Expression.Constant(
@@ -1173,7 +1178,7 @@ private static SqlConstantExpression GetConstantOrNull(Expression expression)
null)
: null;
- private bool TryRewriteContainsEntity(Expression source, Expression item, out Expression result)
+ private bool TryRewriteContainsEntity(Expression source, Expression item, [CA.NotNullWhen(true)] out Expression? result)
{
result = null;
@@ -1244,7 +1249,8 @@ when sqlParameterExpression.Name.StartsWith(QueryCompilationContext.QueryParamet
return true;
}
- private bool TryRewriteEntityEquality(ExpressionType nodeType, Expression left, Expression right, bool equalsMethod, out Expression result)
+ private bool TryRewriteEntityEquality(
+ ExpressionType nodeType, Expression left, Expression right, bool equalsMethod, [CA.NotNullWhen(true)] out Expression? result)
{
var leftEntityReference = left as EntityReferenceExpression;
var rightEntityReference = right as EntityReferenceExpression;
@@ -1259,7 +1265,7 @@ private bool TryRewriteEntityEquality(ExpressionType nodeType, Expression left,
if (IsNullSqlConstantExpression(left)
|| IsNullSqlConstantExpression(right))
{
- var nonNullEntityReference = IsNullSqlConstantExpression(left) ? rightEntityReference : leftEntityReference;
+ var nonNullEntityReference = (IsNullSqlConstantExpression(left) ? rightEntityReference : leftEntityReference)!;
var entityType1 = nonNullEntityReference.EntityType;
if (entityType1.GetViewOrTableMappings().FirstOrDefault()?.Table.IsOptional(entityType1) == true)
@@ -1424,6 +1430,7 @@ when memberInitExpression.Bindings.SingleOrDefault(
}
}
+#nullable disable
private static T ParameterValueExtractor(QueryContext context, string baseParameterName, IProperty property)
{
var baseParameter = context.ParameterValues[baseParameterName];
@@ -1443,6 +1450,7 @@ private static List ParameterListValueExtractor(
var getter = property.GetGetter();
return baseListParameter.Select(e => e != null ? (TProperty)getter.GetClrValue(e) : (TProperty)(object)null).ToList();
}
+#nullable enable
private static bool CanEvaluate(Expression expression)
{
@@ -1470,7 +1478,7 @@ private static bool IsNullSqlConstantExpression(Expression expression)
=> expression is SqlConstantExpression sqlConstant && sqlConstant.Value == null;
[DebuggerStepThrough]
- private static bool TranslationFailed(Expression original, Expression translation, out SqlExpression castTranslation)
+ private static bool TranslationFailed(Expression? original, Expression? translation, out SqlExpression? castTranslation)
{
if (original != null
&& !(translation is SqlExpression))
@@ -1504,17 +1512,17 @@ private EntityReferenceExpression(EntityReferenceExpression entityReferenceExpre
EntityType = entityType;
}
- public EntityShaperExpression ParameterEntity { get; }
- public ShapedQueryExpression SubqueryEntity { get; }
+ public EntityShaperExpression? ParameterEntity { get; }
+ public ShapedQueryExpression? SubqueryEntity { get; }
public IEntityType EntityType { get; }
public override Type Type
- => EntityType.ClrType;
+ => EntityType.ClrType!;
public override ExpressionType NodeType
=> ExpressionType.Extension;
- public Expression Convert(Type type)
+ public Expression? Convert(Type type)
{
if (type == typeof(object) // Ignore object conversion
|| type.IsAssignableFrom(Type)) // Ignore casting to base type/interface
@@ -1537,7 +1545,7 @@ public GroupingElementExpression(Expression element)
public Expression Element { get; private set; }
public bool IsDistinct { get; private set; }
- public SqlExpression Predicate { get; private set; }
+ public SqlExpression? Predicate { get; private set; }
public GroupingElementExpression ApplyDistinct()
{
diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorDependencies.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorDependencies.cs
index 9a2ff5617de..eb3c9cacb59 100644
--- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorDependencies.cs
+++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorDependencies.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/SqlExpressionFactory.cs b/src/EFCore.Relational/Query/SqlExpressionFactory.cs
index 7ec38bd5960..0e0440f60b8 100644
--- a/src/EFCore.Relational/Query/SqlExpressionFactory.cs
+++ b/src/EFCore.Relational/Query/SqlExpressionFactory.cs
@@ -13,6 +13,9 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+using CA = System.Diagnostics.CodeAnalysis;
+
+#nullable enable
namespace Microsoft.EntityFrameworkCore.Query
{
@@ -35,7 +38,8 @@ public SqlExpressionFactory([NotNull] SqlExpressionFactoryDependencies dependenc
}
///
- public virtual SqlExpression ApplyDefaultTypeMapping(SqlExpression sqlExpression)
+ [return: CA.NotNullIfNotNull("sqlExpression")]
+ public virtual SqlExpression? ApplyDefaultTypeMapping(SqlExpression? sqlExpression)
{
return sqlExpression == null
|| sqlExpression.TypeMapping != null
@@ -48,7 +52,8 @@ public virtual SqlExpression ApplyDefaultTypeMapping(SqlExpression sqlExpression
}
///
- public virtual SqlExpression ApplyTypeMapping(SqlExpression sqlExpression, RelationalTypeMapping typeMapping)
+ [return: CA.NotNullIfNotNull("sqlExpression")]
+ public virtual SqlExpression? ApplyTypeMapping(SqlExpression? sqlExpression, RelationalTypeMapping? typeMapping)
{
#pragma warning disable IDE0046 // Convert to conditional expression
if (sqlExpression == null
@@ -92,7 +97,7 @@ private SqlExpression ApplyTypeMappingOnLike(LikeExpression likeExpression)
private SqlExpression ApplyTypeMappingOnCase(
CaseExpression caseExpression,
- RelationalTypeMapping typeMapping)
+ RelationalTypeMapping? typeMapping)
{
var whenClauses = new List();
foreach (var caseWhenClause in caseExpression.WhenClauses)
@@ -110,21 +115,21 @@ private SqlExpression ApplyTypeMappingOnCase(
private SqlExpression ApplyTypeMappingOnCollate(
CollateExpression collateExpression,
- RelationalTypeMapping typeMapping)
+ RelationalTypeMapping? typeMapping)
=> collateExpression.Update(ApplyTypeMapping(collateExpression.Operand, typeMapping));
private SqlExpression ApplyTypeMappingOnDistinct(
DistinctExpression distinctExpression,
- RelationalTypeMapping typeMapping)
+ RelationalTypeMapping? typeMapping)
=> distinctExpression.Update(ApplyTypeMapping(distinctExpression.Operand, typeMapping));
private SqlExpression ApplyTypeMappingOnSqlUnary(
SqlUnaryExpression sqlUnaryExpression,
- RelationalTypeMapping typeMapping)
+ RelationalTypeMapping? typeMapping)
{
SqlExpression operand;
Type resultType;
- RelationalTypeMapping resultTypeMapping;
+ RelationalTypeMapping? resultTypeMapping;
switch (sqlUnaryExpression.OperatorType)
{
case ExpressionType.Equal:
@@ -164,14 +169,14 @@ private SqlExpression ApplyTypeMappingOnSqlUnary(
private SqlExpression ApplyTypeMappingOnSqlBinary(
SqlBinaryExpression sqlBinaryExpression,
- RelationalTypeMapping typeMapping)
+ RelationalTypeMapping? typeMapping)
{
var left = sqlBinaryExpression.Left;
var right = sqlBinaryExpression.Right;
Type resultType;
- RelationalTypeMapping resultTypeMapping;
- RelationalTypeMapping inferredTypeMapping;
+ RelationalTypeMapping? resultTypeMapping;
+ RelationalTypeMapping? inferredTypeMapping;
switch (sqlBinaryExpression.OperatorType)
{
case ExpressionType.Equal:
@@ -229,11 +234,11 @@ private SqlExpression ApplyTypeMappingOnSqlBinary(
}
///
- public virtual SqlBinaryExpression MakeBinary(
+ public virtual SqlBinaryExpression? MakeBinary(
ExpressionType operatorType,
SqlExpression left,
SqlExpression right,
- RelationalTypeMapping typeMapping)
+ RelationalTypeMapping? typeMapping)
{
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
@@ -268,7 +273,7 @@ public virtual SqlBinaryExpression Equal(SqlExpression left, SqlExpression right
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.Equal, left, right, null);
+ return MakeBinary(ExpressionType.Equal, left, right, null)!;
}
///
@@ -277,7 +282,7 @@ public virtual SqlBinaryExpression NotEqual(SqlExpression left, SqlExpression ri
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.NotEqual, left, right, null);
+ return MakeBinary(ExpressionType.NotEqual, left, right, null)!;
}
///
@@ -286,7 +291,7 @@ public virtual SqlBinaryExpression GreaterThan(SqlExpression left, SqlExpression
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.GreaterThan, left, right, null);
+ return MakeBinary(ExpressionType.GreaterThan, left, right, null)!;
}
///
@@ -295,7 +300,7 @@ public virtual SqlBinaryExpression GreaterThanOrEqual(SqlExpression left, SqlExp
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.GreaterThanOrEqual, left, right, null);
+ return MakeBinary(ExpressionType.GreaterThanOrEqual, left, right, null)!;
}
///
@@ -304,7 +309,7 @@ public virtual SqlBinaryExpression LessThan(SqlExpression left, SqlExpression ri
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.LessThan, left, right, null);
+ return MakeBinary(ExpressionType.LessThan, left, right, null)!;
}
///
@@ -313,7 +318,7 @@ public virtual SqlBinaryExpression LessThanOrEqual(SqlExpression left, SqlExpres
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.LessThanOrEqual, left, right, null);
+ return MakeBinary(ExpressionType.LessThanOrEqual, left, right, null)!;
}
///
@@ -322,7 +327,7 @@ public virtual SqlBinaryExpression AndAlso(SqlExpression left, SqlExpression rig
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.AndAlso, left, right, null);
+ return MakeBinary(ExpressionType.AndAlso, left, right, null)!;
}
///
@@ -331,74 +336,74 @@ public virtual SqlBinaryExpression OrElse(SqlExpression left, SqlExpression righ
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.OrElse, left, right, null);
+ return MakeBinary(ExpressionType.OrElse, left, right, null)!;
}
///
- public virtual SqlBinaryExpression Add(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null)
+ public virtual SqlBinaryExpression Add(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)
{
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.Add, left, right, typeMapping);
+ return MakeBinary(ExpressionType.Add, left, right, typeMapping)!;
}
///
- public virtual SqlBinaryExpression Subtract(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null)
+ public virtual SqlBinaryExpression Subtract(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)
{
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.Subtract, left, right, typeMapping);
+ return MakeBinary(ExpressionType.Subtract, left, right, typeMapping)!;
}
///
- public virtual SqlBinaryExpression Multiply(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null)
+ public virtual SqlBinaryExpression Multiply(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)
{
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.Multiply, left, right, typeMapping);
+ return MakeBinary(ExpressionType.Multiply, left, right, typeMapping)!;
}
///
- public virtual SqlBinaryExpression Divide(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null)
+ public virtual SqlBinaryExpression Divide(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)
{
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.Divide, left, right, typeMapping);
+ return MakeBinary(ExpressionType.Divide, left, right, typeMapping)!;
}
///
- public virtual SqlBinaryExpression Modulo(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null)
+ public virtual SqlBinaryExpression Modulo(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)
{
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.Modulo, left, right, typeMapping);
+ return MakeBinary(ExpressionType.Modulo, left, right, typeMapping)!;
}
///
- public virtual SqlBinaryExpression And(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null)
+ public virtual SqlBinaryExpression And(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)
{
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.And, left, right, typeMapping);
+ return MakeBinary(ExpressionType.And, left, right, typeMapping)!;
}
///
- public virtual SqlBinaryExpression Or(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null)
+ public virtual SqlBinaryExpression Or(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)
{
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
- return MakeBinary(ExpressionType.Or, left, right, typeMapping);
+ return MakeBinary(ExpressionType.Or, left, right, typeMapping)!;
}
///
- public virtual SqlFunctionExpression Coalesce(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null)
+ public virtual SqlFunctionExpression Coalesce(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null)
{
Check.NotNull(left, nameof(left));
Check.NotNull(right, nameof(right));
@@ -424,11 +429,11 @@ public virtual SqlFunctionExpression Coalesce(SqlExpression left, SqlExpression
}
///
- public virtual SqlUnaryExpression MakeUnary(
+ public virtual SqlUnaryExpression? MakeUnary(
ExpressionType operatorType,
SqlExpression operand,
Type type,
- RelationalTypeMapping typeMapping = null)
+ RelationalTypeMapping? typeMapping = null)
{
Check.NotNull(operatorType, nameof(operand));
Check.NotNull(operand, nameof(operand));
@@ -444,7 +449,7 @@ public virtual SqlUnaryExpression IsNull(SqlExpression operand)
{
Check.NotNull(operand, nameof(operand));
- return MakeUnary(ExpressionType.Equal, operand, typeof(bool));
+ return MakeUnary(ExpressionType.Equal, operand, typeof(bool))!;
}
///
@@ -452,16 +457,16 @@ public virtual SqlUnaryExpression IsNotNull(SqlExpression operand)
{
Check.NotNull(operand, nameof(operand));
- return MakeUnary(ExpressionType.NotEqual, operand, typeof(bool));
+ return MakeUnary(ExpressionType.NotEqual, operand, typeof(bool))!;
}
///
- public virtual SqlUnaryExpression Convert(SqlExpression operand, Type type, RelationalTypeMapping typeMapping = null)
+ public virtual SqlUnaryExpression Convert(SqlExpression operand, Type type, RelationalTypeMapping? typeMapping = null)
{
Check.NotNull(operand, nameof(operand));
Check.NotNull(type, nameof(type));
- return MakeUnary(ExpressionType.Convert, operand, type.UnwrapNullableType(), typeMapping);
+ return MakeUnary(ExpressionType.Convert, operand, type.UnwrapNullableType(), typeMapping)!;
}
///
@@ -469,7 +474,7 @@ public virtual SqlUnaryExpression Not(SqlExpression operand)
{
Check.NotNull(operand, nameof(operand));
- return MakeUnary(ExpressionType.Not, operand, operand.Type, operand.TypeMapping);
+ return MakeUnary(ExpressionType.Not, operand, operand.Type, operand.TypeMapping)!;
}
///
@@ -477,7 +482,7 @@ public virtual SqlUnaryExpression Negate(SqlExpression operand)
{
Check.NotNull(operand, nameof(operand));
- return MakeUnary(ExpressionType.Negate, operand, operand.Type, operand.TypeMapping);
+ return MakeUnary(ExpressionType.Negate, operand, operand.Type, operand.TypeMapping)!;
}
///
@@ -491,7 +496,7 @@ public virtual CaseExpression Case(SqlExpression operand, params CaseWhenClause[
}
///
- public virtual CaseExpression Case(SqlExpression operand, IReadOnlyList whenClauses, SqlExpression elseResult)
+ public virtual CaseExpression Case(SqlExpression? operand, IReadOnlyList whenClauses, SqlExpression? elseResult)
{
Check.NotNull(operand, nameof(operand));
Check.NotNull(whenClauses, nameof(whenClauses));
@@ -522,7 +527,7 @@ public virtual CaseExpression Case(SqlExpression operand, IReadOnlyList
- public virtual CaseExpression Case(IReadOnlyList whenClauses, SqlExpression elseResult)
+ public virtual CaseExpression Case(IReadOnlyList whenClauses, SqlExpression? elseResult)
{
Check.NotNull(whenClauses, nameof(whenClauses));
@@ -549,21 +554,23 @@ public virtual SqlFunctionExpression Function(
string name,
IEnumerable arguments,
Type returnType,
- RelationalTypeMapping typeMapping = null)
+ RelationalTypeMapping? typeMapping = null)
=> Function(
name, arguments, nullable: true, argumentsPropagateNullability: arguments.Select(a => false), returnType, typeMapping);
///
[Obsolete("Use overload that explicitly specifies value for 'argumentsPropagateNullability' argument.")]
public virtual SqlFunctionExpression Function(
- string schema,
+ string? schema,
string name,
IEnumerable arguments,
Type returnType,
- RelationalTypeMapping typeMapping = null)
- => Function(
- schema, name, arguments, nullable: true, argumentsPropagateNullability: arguments.Select(a => false), returnType,
- typeMapping);
+ RelationalTypeMapping? typeMapping = null)
+ => schema != null
+ ? Function(
+ schema, name, arguments, nullable: true, argumentsPropagateNullability: arguments.Select(a => false), returnType, typeMapping)
+ : Function(
+ name, arguments, nullable: true, argumentsPropagateNullability: arguments.Select(a => false), returnType, typeMapping);
///
[Obsolete(
@@ -573,7 +580,7 @@ public virtual SqlFunctionExpression Function(
string name,
IEnumerable arguments,
Type returnType,
- RelationalTypeMapping typeMapping = null)
+ RelationalTypeMapping? typeMapping = null)
=> Function(
instance,
name,
@@ -586,12 +593,12 @@ public virtual SqlFunctionExpression Function(
///
[Obsolete("Use NiladicFunction method.")]
- public virtual SqlFunctionExpression Function(string name, Type returnType, RelationalTypeMapping typeMapping = null)
+ public virtual SqlFunctionExpression Function(string name, Type returnType, RelationalTypeMapping? typeMapping = null)
=> NiladicFunction(name, nullable: true, returnType, typeMapping);
///
[Obsolete("Use NiladicFunction method.")]
- public virtual SqlFunctionExpression Function(string schema, string name, Type returnType, RelationalTypeMapping typeMapping = null)
+ public virtual SqlFunctionExpression Function(string schema, string name, Type returnType, RelationalTypeMapping? typeMapping = null)
=> NiladicFunction(schema, name, nullable: true, returnType, typeMapping);
///
@@ -600,7 +607,7 @@ public virtual SqlFunctionExpression Function(
SqlExpression instance,
string name,
Type returnType,
- RelationalTypeMapping typeMapping = null)
+ RelationalTypeMapping? typeMapping = null)
=> NiladicFunction(instance, name, nullable: true, instancePropagatesNullability: false, returnType, typeMapping);
///
@@ -610,7 +617,7 @@ public virtual SqlFunctionExpression Function(
bool nullable,
IEnumerable argumentsPropagateNullability,
Type returnType,
- RelationalTypeMapping typeMapping = null)
+ RelationalTypeMapping? typeMapping = null)
{
Check.NotEmpty(name, nameof(name));
Check.NotNull(arguments, nameof(arguments));
@@ -635,8 +642,9 @@ public virtual SqlFunctionExpression Function(
bool nullable,
IEnumerable argumentsPropagateNullability,
Type returnType,
- RelationalTypeMapping typeMapping = null)
+ RelationalTypeMapping? typeMapping = null)
{
+ Check.NotNull(schema, nameof(schema));
Check.NotEmpty(name, nameof(name));
Check.NotNull(arguments, nameof(arguments));
Check.NotNull(argumentsPropagateNullability, nameof(argumentsPropagateNullability));
@@ -661,7 +669,7 @@ public virtual SqlFunctionExpression Function(
bool instancePropagatesNullability,
IEnumerable argumentsPropagateNullability,
Type returnType,
- RelationalTypeMapping typeMapping = null)
+ RelationalTypeMapping? typeMapping = null)
{
Check.NotNull(instance, nameof(instance));
Check.NotEmpty(name, nameof(name));
@@ -686,7 +694,7 @@ public virtual SqlFunctionExpression NiladicFunction(
string name,
bool nullable,
Type returnType,
- RelationalTypeMapping typeMapping = null)
+ RelationalTypeMapping? typeMapping = null)
{
Check.NotEmpty(name, nameof(name));
Check.NotNull(returnType, nameof(returnType));
@@ -700,7 +708,7 @@ public virtual SqlFunctionExpression NiladicFunction(
string name,
bool nullable,
Type returnType,
- RelationalTypeMapping typeMapping = null)
+ RelationalTypeMapping? typeMapping = null)
{
Check.NotEmpty(schema, nameof(schema));
Check.NotEmpty(name, nameof(name));
@@ -716,7 +724,7 @@ public virtual SqlFunctionExpression NiladicFunction(
bool nullable,
bool instancePropagatesNullability,
Type returnType,
- RelationalTypeMapping typeMapping = null)
+ RelationalTypeMapping? typeMapping = null)
{
Check.NotNull(instance, nameof(instance));
Check.NotEmpty(name, nameof(name));
@@ -762,7 +770,7 @@ public virtual InExpression In(SqlExpression item, SelectExpression subquery, bo
}
///
- public virtual LikeExpression Like(SqlExpression match, SqlExpression pattern, SqlExpression escapeChar = null)
+ public virtual LikeExpression Like(SqlExpression match, SqlExpression pattern, SqlExpression? escapeChar = null)
{
Check.NotNull(match, nameof(match));
Check.NotNull(pattern, nameof(pattern));
@@ -779,11 +787,11 @@ public virtual SqlFragmentExpression Fragment(string sql)
}
///
- public virtual SqlConstantExpression Constant(object value, RelationalTypeMapping typeMapping = null)
+ public virtual SqlConstantExpression Constant(object? value, RelationalTypeMapping? typeMapping = null)
=> new SqlConstantExpression(Expression.Constant(value), typeMapping);
///
- public virtual SelectExpression Select(SqlExpression projection)
+ public virtual SelectExpression Select(SqlExpression? projection)
=> new SelectExpression(projection);
///
@@ -824,7 +832,7 @@ public virtual SelectExpression Select(IEntityType entityType, string sql, Expre
return selectExpression;
}
- private void AddSelfConditions(SelectExpression selectExpression, IEntityType entityType, ITableBase table = null)
+ private void AddSelfConditions(SelectExpression selectExpression, IEntityType entityType, ITableBase? table = null)
{
// Add conditions if TPH
var discriminatorAdded = AddDiscriminatorCondition(selectExpression, entityType);
@@ -843,7 +851,7 @@ private void AddSelfConditions(SelectExpression selectExpression, IEntityType en
}
}
- private void AddConditions(SelectExpression selectExpression, IEntityType entityType, ITableBase table = null)
+ private void AddConditions(SelectExpression selectExpression, IEntityType entityType, ITableBase? table = null)
{
AddSelfConditions(selectExpression, entityType, table);
// Add inner join to principal if table sharing
@@ -870,7 +878,7 @@ private void AddConditions(SelectExpression selectExpression, IEntityType entity
}
}
- private void AddInnerJoin(SelectExpression selectExpression, IForeignKey foreignKey, ITableBase table)
+ private void AddInnerJoin(SelectExpression selectExpression, IForeignKey foreignKey, ITableBase? table)
{
var outerEntityProjection = GetMappedEntityProjectionExpression(selectExpression);
var outerIsPrincipal = foreignKey.PrincipalEntityType.IsAssignableFrom(outerEntityProjection.EntityType);
@@ -932,7 +940,7 @@ private void AddOptionalDependentConditions(
IEntityType entityType,
ITableBase table)
{
- SqlExpression predicate = null;
+ SqlExpression? predicate = null;
var requiredNonPkProperties = entityType.GetProperties().Where(p => !p.IsNullable && !p.IsPrimaryKey()).ToList();
if (requiredNonPkProperties.Count > 0)
{
@@ -988,9 +996,7 @@ private void AddOptionalDependentConditions(
var sameTable = table.EntityTypeMappings.Any(m => m.EntityType == referencingFk.DeclaringEntityType)
&& table.IsOptional(referencingFk.DeclaringEntityType);
- AddInnerJoin(
- otherSelectExpression, referencingFk,
- sameTable ? table : null);
+ AddInnerJoin(otherSelectExpression, referencingFk, sameTable ? table : null);
selectExpression.ApplyUnion(otherSelectExpression, distinct: true);
}
@@ -1006,7 +1012,7 @@ private SqlExpression IsNotNull(IProperty property, EntityProjectionExpression e
///
[Obsolete("Use IRelationalTypeMappingSource directly.")]
- public virtual RelationalTypeMapping GetTypeMappingForValue(object value)
+ public virtual RelationalTypeMapping GetTypeMappingForValue(object? value)
=> _typeMappingSource.GetMappingForValue(value);
///
diff --git a/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs b/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs
index c9ddb288c9b..eac04fa5f32 100644
--- a/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs
+++ b/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/SqlExpressionVisitor.cs b/src/EFCore.Relational/Query/SqlExpressionVisitor.cs
index 298b6cbf936..ae6526e9e5e 100644
--- a/src/EFCore.Relational/Query/SqlExpressionVisitor.cs
+++ b/src/EFCore.Relational/Query/SqlExpressionVisitor.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query
{
///
diff --git a/src/EFCore.Relational/Query/SqlExpressions/CaseExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/CaseExpression.cs
index f1104cca64b..898a47440c9 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/CaseExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/CaseExpression.cs
@@ -8,6 +8,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -32,7 +34,7 @@ public class CaseExpression : SqlExpression
public CaseExpression(
[NotNull] SqlExpression operand,
[NotNull] IReadOnlyList whenClauses,
- [CanBeNull] SqlExpression elseResult = null)
+ [CanBeNull] SqlExpression? elseResult = null)
: base(Check.NotEmpty(whenClauses, nameof(whenClauses))[0].Result.Type, whenClauses[0].Result.TypeMapping)
{
Check.NotNull(operand, nameof(operand));
@@ -49,7 +51,7 @@ public CaseExpression(
/// A value to return if no matches, if any.
public CaseExpression(
[NotNull] IReadOnlyList whenClauses,
- [CanBeNull] SqlExpression elseResult = null)
+ [CanBeNull] SqlExpression? elseResult = null)
: base(Check.NotEmpty(whenClauses, nameof(whenClauses))[0].Result.Type, whenClauses[0].Result.TypeMapping)
{
_whenClauses.AddRange(whenClauses);
@@ -59,7 +61,7 @@ public CaseExpression(
///
/// The value to compare in .
///
- public virtual SqlExpression Operand { get; }
+ public virtual SqlExpression? Operand { get; }
///
/// The list of to match or evaluate condition to get result.
@@ -70,14 +72,14 @@ public virtual IReadOnlyList WhenClauses
///
/// The value to return if none of the matches.
///
- public virtual SqlExpression ElseResult { get; }
+ public virtual SqlExpression? ElseResult { get; }
///
protected override Expression VisitChildren(ExpressionVisitor visitor)
{
Check.NotNull(visitor, nameof(visitor));
- var operand = (SqlExpression)visitor.Visit(Operand);
+ var operand = (SqlExpression?)visitor.Visit(Operand);
var changed = operand != Operand;
var whenClauses = new List();
foreach (var whenClause in WhenClauses)
@@ -97,7 +99,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
}
}
- var elseResult = (SqlExpression)visitor.Visit(ElseResult);
+ var elseResult = (SqlExpression?)visitor.Visit(ElseResult);
changed |= elseResult != ElseResult;
return changed
@@ -116,11 +118,11 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
/// The property of the result.
/// This expression if no children changed, or an expression with the updated children.
public virtual CaseExpression Update(
- [CanBeNull] SqlExpression operand,
+ [CanBeNull] SqlExpression? operand,
[NotNull] IReadOnlyList whenClauses,
- [CanBeNull] SqlExpression elseResult)
+ [CanBeNull] SqlExpression? elseResult)
=> operand != Operand || !whenClauses.SequenceEqual(WhenClauses) || elseResult != ElseResult
- ? (Operand == null
+ ? (operand == null
? new CaseExpression(whenClauses, elseResult)
: new CaseExpression(operand, whenClauses, elseResult))
: this;
@@ -158,7 +160,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is CaseExpression caseExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/CaseWhenClause.cs b/src/EFCore.Relational/Query/SqlExpressions/CaseWhenClause.cs
index c6419239045..06c63154ea5 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/CaseWhenClause.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/CaseWhenClause.cs
@@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -43,7 +45,7 @@ public CaseWhenClause([NotNull] SqlExpression test, [NotNull] SqlExpression resu
public virtual SqlExpression Result { get; }
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is CaseWhenClause caseWhenClause
diff --git a/src/EFCore.Relational/Query/SqlExpressions/CollateExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/CollateExpression.cs
index 9af5508e4b7..23970328a37 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/CollateExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/CollateExpression.cs
@@ -6,6 +6,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -79,7 +81,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is CollateExpression collateExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/ColumnExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ColumnExpression.cs
index 84783d07f19..ba964a9aefe 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/ColumnExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/ColumnExpression.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -41,7 +43,7 @@ internal ColumnExpression(IProperty property, IColumnBase column, TableExpressio
internal ColumnExpression(ProjectionExpression subqueryProjection, TableExpressionBase table)
: this(
subqueryProjection.Alias, table,
- subqueryProjection.Type, subqueryProjection.Expression.TypeMapping,
+ subqueryProjection.Type, subqueryProjection.Expression.TypeMapping!,
IsNullableProjection(subqueryProjection))
{
}
@@ -94,19 +96,19 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
///
/// A new expression which has property set to true.
public ColumnExpression MakeNullable()
- => new ColumnExpression(Name, Table, Type, TypeMapping, true);
+ => new ColumnExpression(Name, Table, Type, TypeMapping!, true);
///
protected override void Print(ExpressionPrinter expressionPrinter)
{
Check.NotNull(expressionPrinter, nameof(expressionPrinter));
- expressionPrinter.Append(Table.Alias).Append(".");
+ expressionPrinter.Append(Table.Alias!).Append(".");
expressionPrinter.Append(Name);
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is ColumnExpression columnExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/CrossApplyExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/CrossApplyExpression.cs
index 0d595ea0b5e..b57c3ab0086 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/CrossApplyExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/CrossApplyExpression.cs
@@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -60,7 +62,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is CrossApplyExpression crossApplyExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/CrossJoinExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/CrossJoinExpression.cs
index a74aca9a8fd..26a399855ed 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/CrossJoinExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/CrossJoinExpression.cs
@@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -60,7 +62,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is CrossJoinExpression crossJoinExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/DistinctExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/DistinctExpression.cs
index ef16ba7fdd0..09e27839bec 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/DistinctExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/DistinctExpression.cs
@@ -6,6 +6,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -70,7 +72,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is DistinctExpression distinctExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/ExceptExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ExceptExpression.cs
index 3605645ee6b..7b4f55d045e 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/ExceptExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/ExceptExpression.cs
@@ -6,6 +6,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -59,7 +61,7 @@ public virtual ExceptExpression Update([NotNull] SelectExpression source1, [NotN
Check.NotNull(source2, nameof(source2));
return source1 != Source1 || source2 != Source2
- ? new ExceptExpression(Alias, source1, source2, IsDistinct)
+ ? new ExceptExpression(Alias!, source1, source2, IsDistinct)
: this;
}
@@ -87,7 +89,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is ExceptExpression exceptExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs
index af5e6ccc6b9..39c631d31c7 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -29,7 +31,7 @@ public class ExistsExpression : SqlExpression
public ExistsExpression(
[NotNull] SelectExpression subquery,
bool negated,
- [CanBeNull] RelationalTypeMapping typeMapping)
+ [CanBeNull] RelationalTypeMapping? typeMapping)
: base(typeof(bool), typeMapping)
{
Check.NotNull(subquery, nameof(subquery));
@@ -91,7 +93,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is ExistsExpression existsExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs
index 29935de2659..08738af05d1 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs
@@ -6,6 +6,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -73,7 +75,7 @@ public virtual FromSqlExpression Update([NotNull] Expression arguments)
Check.NotNull(arguments, nameof(arguments));
return arguments != Arguments
- ? new FromSqlExpression(Alias, Sql, arguments)
+ ? new FromSqlExpression(Alias!, Sql, arguments)
: this;
}
@@ -94,7 +96,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is FromSqlExpression fromSqlExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs
index dc22978b44a..29b52513cae 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -34,7 +36,7 @@ public InExpression(
[NotNull] SqlExpression item,
bool negated,
[NotNull] SelectExpression subquery,
- [CanBeNull] RelationalTypeMapping typeMapping)
+ [CanBeNull] RelationalTypeMapping? typeMapping)
: this(Check.NotNull(item, nameof(item)), null, Check.NotNull(subquery, nameof(subquery)), negated, typeMapping)
{
}
@@ -51,7 +53,7 @@ public InExpression(
[NotNull] SqlExpression item,
bool negated,
[NotNull] SqlExpression values,
- [CanBeNull] RelationalTypeMapping typeMapping)
+ [CanBeNull] RelationalTypeMapping? typeMapping)
: this(Check.NotNull(item, nameof(item)), Check.NotNull(values, nameof(values)), null, negated, typeMapping)
{
}
@@ -67,7 +69,7 @@ public InExpression(
[NotNull] SqlExpression item,
[NotNull] SelectExpression subquery,
bool negated,
- [CanBeNull] RelationalTypeMapping typeMapping)
+ [CanBeNull] RelationalTypeMapping? typeMapping)
: this(Check.NotNull(item, nameof(item)), null, Check.NotNull(subquery, nameof(subquery)), negated, typeMapping)
{
}
@@ -83,17 +85,17 @@ public InExpression(
[NotNull] SqlExpression item,
[NotNull] SqlExpression values,
bool negated,
- [CanBeNull] RelationalTypeMapping typeMapping)
+ [CanBeNull] RelationalTypeMapping? typeMapping)
: this(Check.NotNull(item, nameof(item)), Check.NotNull(values, nameof(values)), null, negated, typeMapping)
{
}
private InExpression(
SqlExpression item,
- SqlExpression values,
- SelectExpression subquery,
+ SqlExpression? values,
+ SelectExpression? subquery,
bool negated,
- RelationalTypeMapping typeMapping)
+ RelationalTypeMapping? typeMapping)
: base(typeof(bool), typeMapping)
{
Item = item;
@@ -115,12 +117,12 @@ private InExpression(
///
/// The list of values to search item in.
///
- public virtual SqlExpression Values { get; }
+ public virtual SqlExpression? Values { get; }
///
/// The subquery to search item in.
///
- public virtual SelectExpression Subquery { get; }
+ public virtual SelectExpression? Subquery { get; }
///
protected override Expression VisitChildren(ExpressionVisitor visitor)
@@ -128,8 +130,8 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
Check.NotNull(visitor, nameof(visitor));
var item = (SqlExpression)visitor.Visit(Item);
- var subquery = (SelectExpression)visitor.Visit(Subquery);
- var values = (SqlExpression)visitor.Visit(Values);
+ var subquery = (SelectExpression?)visitor.Visit(Subquery);
+ var values = (SqlExpression?)visitor.Visit(Values);
return Update(item, values, subquery);
}
@@ -151,8 +153,8 @@ public virtual InExpression Negate()
/// This expression if no children changed, or an expression with the updated children.
public virtual InExpression Update(
[NotNull] SqlExpression item,
- [CanBeNull] SqlExpression values,
- [CanBeNull] SelectExpression subquery)
+ [CanBeNull] SqlExpression? values,
+ [CanBeNull] SelectExpression? subquery)
{
Check.NotNull(item, nameof(item));
@@ -207,7 +209,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is InExpression inExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/InnerJoinExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/InnerJoinExpression.cs
index dc3c4c3aad8..840c8916c8f 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/InnerJoinExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/InnerJoinExpression.cs
@@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -68,7 +70,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is InnerJoinExpression innerJoinExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/IntersectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/IntersectExpression.cs
index 9f5c3cd564a..2639116cc55 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/IntersectExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/IntersectExpression.cs
@@ -6,6 +6,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -59,7 +61,7 @@ public virtual IntersectExpression Update([NotNull] SelectExpression source1, [N
Check.NotNull(source2, nameof(source2));
return source1 != Source1 || source2 != Source2
- ? new IntersectExpression(Alias, source1, source2, IsDistinct)
+ ? new IntersectExpression(Alias!, source1, source2, IsDistinct)
: this;
}
@@ -87,7 +89,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is IntersectExpression intersectExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/JoinExpressionBase.cs b/src/EFCore.Relational/Query/SqlExpressions/JoinExpressionBase.cs
index 8713904293e..0ef4bfd35c4 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/JoinExpressionBase.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/JoinExpressionBase.cs
@@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -36,7 +38,7 @@ protected JoinExpressionBase([NotNull] TableExpressionBase table)
public virtual TableExpressionBase Table { get; }
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is JoinExpressionBase joinExpressionBase
diff --git a/src/EFCore.Relational/Query/SqlExpressions/LeftJoinExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/LeftJoinExpression.cs
index 3f46e73e1ef..5aa05213064 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/LeftJoinExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/LeftJoinExpression.cs
@@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -68,7 +70,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is LeftJoinExpression leftJoinExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/LikeExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/LikeExpression.cs
index f546c1c8241..818ab2fa571 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/LikeExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/LikeExpression.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -30,8 +32,8 @@ public class LikeExpression : SqlExpression
public LikeExpression(
[NotNull] SqlExpression match,
[NotNull] SqlExpression pattern,
- [CanBeNull] SqlExpression escapeChar,
- [CanBeNull] RelationalTypeMapping typeMapping)
+ [CanBeNull] SqlExpression? escapeChar,
+ [CanBeNull] RelationalTypeMapping? typeMapping)
: base(typeof(bool), typeMapping)
{
Check.NotNull(match, nameof(match));
@@ -55,7 +57,7 @@ public LikeExpression(
///
/// The escape chater to use in LIKE.
///
- public virtual SqlExpression EscapeChar { get; }
+ public virtual SqlExpression? EscapeChar { get; }
///
protected override Expression VisitChildren(ExpressionVisitor visitor)
@@ -64,7 +66,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
var match = (SqlExpression)visitor.Visit(Match);
var pattern = (SqlExpression)visitor.Visit(Pattern);
- var escapeChar = (SqlExpression)visitor.Visit(EscapeChar);
+ var escapeChar = (SqlExpression?)visitor.Visit(EscapeChar);
return Update(match, pattern, escapeChar);
}
@@ -80,7 +82,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
public virtual LikeExpression Update(
[NotNull] SqlExpression match,
[NotNull] SqlExpression pattern,
- [CanBeNull] SqlExpression escapeChar)
+ [CanBeNull] SqlExpression? escapeChar)
{
Check.NotNull(match, nameof(match));
Check.NotNull(pattern, nameof(pattern));
@@ -107,7 +109,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is LikeExpression likeExpression
@@ -117,7 +119,7 @@ private bool Equals(LikeExpression likeExpression)
=> base.Equals(likeExpression)
&& Match.Equals(likeExpression.Match)
&& Pattern.Equals(likeExpression.Pattern)
- && EscapeChar.Equals(likeExpression.EscapeChar);
+ && EscapeChar?.Equals(likeExpression.EscapeChar) == true;
///
public override int GetHashCode()
diff --git a/src/EFCore.Relational/Query/SqlExpressions/OrderingExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/OrderingExpression.cs
index 2d59c64561a..289346f92c8 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/OrderingExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/OrderingExpression.cs
@@ -6,6 +6,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -84,7 +86,7 @@ void IPrintableExpression.Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is OrderingExpression orderingExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/OuterApplyExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/OuterApplyExpression.cs
index 22f4d420d93..f03a9a97a66 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/OuterApplyExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/OuterApplyExpression.cs
@@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -60,7 +62,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is OuterApplyExpression outerApplyExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/PredicateJoinExpressionBase.cs b/src/EFCore.Relational/Query/SqlExpressions/PredicateJoinExpressionBase.cs
index e8d914f6a3b..1bc5dc68f2d 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/PredicateJoinExpressionBase.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/PredicateJoinExpressionBase.cs
@@ -5,6 +5,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -37,7 +39,7 @@ protected PredicateJoinExpressionBase([NotNull] TableExpressionBase table, [NotN
public virtual SqlExpression JoinPredicate { get; }
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is PredicateJoinExpressionBase predicateJoinExpressionBase
diff --git a/src/EFCore.Relational/Query/SqlExpressions/ProjectionExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ProjectionExpression.cs
index 00b778a4146..01799e62228 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/ProjectionExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/ProjectionExpression.cs
@@ -6,6 +6,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -85,7 +87,7 @@ void IPrintableExpression.Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is ProjectionExpression projectionExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/RowNumberExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/RowNumberExpression.cs
index a6ce1b94a20..840dbb55467 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/RowNumberExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/RowNumberExpression.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -29,9 +31,9 @@ public class RowNumberExpression : SqlExpression
/// A list of ordering expressions to order by.
/// The associated with the expression.
public RowNumberExpression(
- [CanBeNull] IReadOnlyList partitions,
+ [CanBeNull] IReadOnlyList? partitions,
[NotNull] IReadOnlyList orderings,
- [CanBeNull] RelationalTypeMapping typeMapping)
+ [CanBeNull] RelationalTypeMapping? typeMapping)
: base(typeof(long), typeMapping)
{
Check.NotEmpty(orderings, nameof(orderings));
@@ -85,7 +87,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
/// The property of the result.
/// This expression if no children changed, or an expression with the updated children.
public virtual RowNumberExpression Update(
- [CanBeNull] IReadOnlyList partitions,
+ [CanBeNull] IReadOnlyList? partitions,
[NotNull] IReadOnlyList orderings)
{
Check.NotNull(orderings, nameof(orderings));
@@ -115,7 +117,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is RowNumberExpression rowNumberExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs
index aaad51b0574..d72007687a8 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
///
@@ -86,7 +88,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is ScalarSubqueryExpression scalarSubqueryExpression
diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs
index 51e4e57e795..a8921c30beb 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs
@@ -13,6 +13,9 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+using CA = System.Diagnostics.CodeAnalysis;
+
+#nullable enable
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
{
@@ -59,7 +62,7 @@ private readonly IDictionary _childIdentifiers
= new List<(ColumnExpression Column, ValueComparer Comparer)>();
- private readonly List _pendingCollections = new List();
+ private readonly List _pendingCollections = new List();
private List _tptLeftJoinTables = new List();
private IDictionary _projectionMapping = new Dictionary();
@@ -96,22 +99,22 @@ public IReadOnlyList Orderings
///
/// The WHERE predicate for the SELECT.
///
- public SqlExpression Predicate { get; private set; }
+ public SqlExpression? Predicate { get; private set; }
///
/// The HAVING predicate for the SELECT when clause exists.
///
- public SqlExpression Having { get; private set; }
+ public SqlExpression? Having { get; private set; }
///
/// The limit applied to the number of rows in the result set.
///
- public SqlExpression Limit { get; private set; }
+ public SqlExpression? Limit { get; private set; }
///
/// The offset to skip rows from the result set.
///
- public SqlExpression Offset { get; private set; }
+ public SqlExpression? Offset { get; private set; }
///
/// A bool value indicating if DISTINCT is applied to projection of this .
@@ -130,7 +133,7 @@ public void ApplyTags([NotNull] ISet tags)
}
private SelectExpression(
- string alias,
+ string? alias,
List projections,
List tables,
List groupBy,
@@ -143,7 +146,7 @@ private SelectExpression(
_orderings = orderings;
}
- internal SelectExpression(SqlExpression projection)
+ internal SelectExpression(SqlExpression? projection)
: base(null)
{
if (projection != null)
@@ -184,19 +187,20 @@ internal SelectExpression(IEntityType entityType, ISqlExpressionFactory sqlExpre
var entityProjection = new EntityProjectionExpression(entityType, propertyExpressions);
_projectionMapping[new ProjectionMember()] = entityProjection;
- if (entityType.FindPrimaryKey() != null)
+ var primaryKey = entityType.FindPrimaryKey();
+ if (primaryKey != null)
{
- foreach (var property in entityType.FindPrimaryKey().Properties)
+ foreach (var property in primaryKey.Properties)
{
- _identifier.Add((propertyExpressions[property], property.GetKeyValueComparer()));
+ _identifier.Add((propertyExpressions[property], property.GetKeyValueComparer()!));
}
}
}
else
{
// TPT
- var keyProperties = entityType.FindPrimaryKey().Properties;
- List joinColumns = null;
+ var keyProperties = entityType.FindPrimaryKey()!.Properties;
+ List joinColumns = default!;
var tables = new List();
var columns = new Dictionary();
foreach (var baseType in entityType.GetAllBaseTypesInclusive())
@@ -217,7 +221,7 @@ internal SelectExpression(IEntityType entityType, ISqlExpressionFactory sqlExpre
{
var columnExpression = columns[property];
joinColumns.Add(columnExpression);
- _identifier.Add((columnExpression, property.GetKeyValueComparer()));
+ _identifier.Add((columnExpression, property.GetKeyValueComparer()!));
}
}
else
@@ -298,11 +302,12 @@ internal SelectExpression(IEntityType entityType, TableExpressionBase tableExpre
var entityProjection = new EntityProjectionExpression(entityType, propertyExpressions);
_projectionMapping[new ProjectionMember()] = entityProjection;
- if (entityType.FindPrimaryKey() != null)
+ var primaryKey = entityType.FindPrimaryKey();
+ if (primaryKey != null)
{
- foreach (var property in entityType.FindPrimaryKey().Properties)
+ foreach (var property in primaryKey.Properties)
{
- _identifier.Add((propertyExpressions[property], property.GetKeyValueComparer()));
+ _identifier.Add((propertyExpressions[property], property.GetKeyValueComparer()!));
}
}
}
@@ -424,7 +429,7 @@ public int AddToProjection([NotNull] SqlExpression sqlExpression)
return AddToProjection(sqlExpression, null);
}
- private int AddToProjection(SqlExpression sqlExpression, string alias)
+ private int AddToProjection(SqlExpression sqlExpression, string? alias)
{
var existingIndex = _projection.FindIndex(pe => pe.Expression.Equals(sqlExpression));
if (existingIndex != -1)
@@ -900,7 +905,7 @@ private void ApplySetOperation(SetOperationType setOperationType, SelectExpressi
var innerColumn2 = (SqlExpression)joinedMapping.Value2;
// For now, make sure that both sides output the same store type, otherwise the query may fail.
// TODO: with #15586 we'll be able to also allow different store types which are implicitly convertible to one another.
- if (innerColumn1.TypeMapping.StoreType != innerColumn2.TypeMapping.StoreType)
+ if (innerColumn1.TypeMapping!.StoreType != innerColumn2.TypeMapping!.StoreType)
{
throw new InvalidOperationException(RelationalStrings.SetOperationsOnDifferentStoreTypes);
}
@@ -956,7 +961,8 @@ void HandleEntityProjection(
}
var discriminatorExpression = projection1.DiscriminatorExpression;
- if (projection1.DiscriminatorExpression != null)
+ if (projection1.DiscriminatorExpression != null
+ && projection2.DiscriminatorExpression != null)
{
discriminatorExpression = GenerateDiscriminatorExpression(
select1, projection1.DiscriminatorExpression,
@@ -1031,7 +1037,7 @@ static bool IsNullableProjection(ProjectionExpression projectionExpression)
};
}
- private ColumnExpression GenerateOuterColumn(SqlExpression projection, string alias = null)
+ private ColumnExpression GenerateOuterColumn(SqlExpression projection, string? alias = null)
{
var index = AddToProjection(projection, alias);
return new ColumnExpression(_projection[index], this);
@@ -1054,7 +1060,7 @@ public IDictionary PushdownIntoSubquery()
_tptLeftJoinTables = _tptLeftJoinTables
};
- _tptLeftJoinTables = null;
+ _tptLeftJoinTables = new List();
var projectionMap = new Dictionary();
// Projections may be present if added by lifting SingleResult/Enumerable in projection through join
@@ -1190,7 +1196,7 @@ EntityProjectionExpression LiftEntityProjectionFromSubquery(EntityProjectionExpr
propertyExpressions[property] = outerColumn;
}
- ColumnExpression discriminatorExpression = null;
+ ColumnExpression? discriminatorExpression = null;
if (entityProjection.DiscriminatorExpression != null)
{
discriminatorExpression = subquery.GenerateOuterColumn(
@@ -1234,7 +1240,7 @@ public Expression AddSingleProjection([NotNull] ShapedQueryExpression shapedQuer
var innerExpression = RemoveConvert(shaperExpression);
if (!(innerExpression is EntityShaperExpression))
{
- var sentinelExpression = innerSelectExpression.Limit;
+ var sentinelExpression = innerSelectExpression.Limit!;
var sentinelNullableType = sentinelExpression.Type.MakeNullable();
ProjectionBindingExpression dummyProjection;
if (innerSelectExpression.Projection.Any())
@@ -1331,7 +1337,7 @@ static Expression RemoveConvert(Expression expression)
/// A which represents shaping of this collection.
public CollectionShaperExpression AddCollectionProjection(
[NotNull] ShapedQueryExpression shapedQueryExpression,
- [CanBeNull] INavigationBase navigation,
+ [CanBeNull] INavigationBase? navigation,
[NotNull] Type elementType)
{
Check.NotNull(shapedQueryExpression, nameof(shapedQueryExpression));
@@ -1356,18 +1362,18 @@ public CollectionShaperExpression AddCollectionProjection(
/// The type of the element in the collection.
/// A value indicating whether the collection query would be run with a different DbCommand.
/// An expression which represents shaping of this collection.
- public Expression ApplyCollectionJoin(
+ public Expression? ApplyCollectionJoin(
int collectionIndex,
int collectionId,
[NotNull] Expression innerShaper,
- [CanBeNull] INavigationBase navigation,
+ [CanBeNull] INavigationBase? navigation,
[NotNull] Type elementType,
bool splitQuery = false)
{
Check.NotNull(innerShaper, nameof(innerShaper));
Check.NotNull(elementType, nameof(elementType));
- var innerSelectExpression = _pendingCollections[collectionIndex];
+ var innerSelectExpression = _pendingCollections[collectionIndex]!;
_pendingCollections[collectionIndex] = null;
if (_identifier.Count == 0
@@ -1586,7 +1592,7 @@ public Expression ApplyCollectionJoin(
foreach (var projection in innerSelectExpression._projectionMapping)
{
var value = ((ConstantExpression)projection.Value).Value;
- object mappedValue = null;
+ object? mappedValue = null;
if (value is int index)
{
mappedValue = indexMap[index];
@@ -1602,7 +1608,7 @@ public Expression ApplyCollectionJoin(
mappedValue = newEntityIndexMap;
}
- mapping[projection.Key] = mappedValue;
+ mapping[projection.Key] = mappedValue!;
}
innerShaper = remapper.RemapProjectionMember(innerShaper, mapping, pendingCollectionOffset: 0);
@@ -1685,7 +1691,7 @@ private static SqlExpression MakeNullable(SqlExpression sqlExpression)
return (NewArrayInit(typeof(object), updatedExpressions), comparers);
}
- private SqlExpression TryExtractJoinKey(SelectExpression selectExpression, bool allowNonEquality)
+ private SqlExpression? TryExtractJoinKey(SelectExpression selectExpression, bool allowNonEquality)
{
if (selectExpression.Limit == null
&& selectExpression.Offset == null
@@ -1712,12 +1718,12 @@ private SqlExpression TryExtractJoinKey(SelectExpression selectExpression, bool
return null;
}
- private SqlExpression TryExtractJoinKey(
+ private SqlExpression? TryExtractJoinKey(
SelectExpression selectExpression,
SqlExpression predicate,
List columnExpressions,
bool allowNonEquality,
- out SqlExpression updatedPredicate)
+ out SqlExpression? updatedPredicate)
{
if (predicate is SqlBinaryExpression sqlBinaryExpression)
{
@@ -1747,14 +1753,14 @@ private SqlExpression TryExtractJoinKey(
return null;
}
- private static SqlExpression CombineNonNullExpressions(SqlExpression left, SqlExpression right)
+ private static SqlExpression? CombineNonNullExpressions(SqlExpression? left, SqlExpression? right)
=> left != null
? right != null
? new SqlBinaryExpression(ExpressionType.AndAlso, left, right, left.Type, left.TypeMapping)
: left
: right;
- private SqlBinaryExpression ValidateKeyComparison(
+ private SqlBinaryExpression? ValidateKeyComparison(
SelectExpression inner,
SqlBinaryExpression sqlBinaryExpression,
List columnExpressions,
@@ -1819,7 +1825,7 @@ private SqlBinaryExpression ValidateKeyComparison(
return null;
}
- private SqlExpression RemoveRedundantNullChecks(SqlExpression predicate, List columnExpressions)
+ private SqlExpression? RemoveRedundantNullChecks(SqlExpression predicate, List columnExpressions)
{
if (predicate is SqlBinaryExpression sqlBinaryExpression)
{
@@ -1866,7 +1872,8 @@ public bool ContainsOuterReference(SelectExpression selectExpression)
return _containsOuterReference;
}
- public override Expression Visit(Expression expression)
+ [return: CA.NotNullIfNotNull("expression")]
+ public override Expression? Visit(Expression? expression)
{
if (_containsOuterReference)
{
@@ -1915,7 +1922,7 @@ private Expression AddJoin(
SelectExpression innerSelectExpression,
Expression outerShaper,
Expression innerShaper,
- SqlExpression joinPredicate = null)
+ SqlExpression? joinPredicate = null)
{
var pendingCollectionOffset = _pendingCollections.Count;
AddJoin(joinType, ref innerSelectExpression, joinPredicate);
@@ -2062,13 +2069,13 @@ private sealed class ProjectionBindingExpressionRemappingExpressionVisitor : Exp
private readonly Expression _queryExpression;
// Shifting PMs, converting PMs to index/indexMap
- private IDictionary _projectionMemberMappings;
+ private IDictionary? _projectionMemberMappings;
// Relocating index
- private int[] _indexMap;
+ private int[]? _indexMap;
// Shift pending collection offset
- private int _pendingCollectionOffset;
+ private int? _pendingCollectionOffset;
public ProjectionBindingExpressionRemappingExpressionVisitor(Expression queryExpression)
{
@@ -2110,7 +2117,7 @@ private CollectionShaperExpression Remap(CollectionShaperExpression collectionSh
=> new CollectionShaperExpression(
new ProjectionBindingExpression(
_queryExpression,
- ((ProjectionBindingExpression)collectionShaperExpression.Projection).Index.Value + _pendingCollectionOffset,
+ ((ProjectionBindingExpression)collectionShaperExpression.Projection).Index!.Value + (int)_pendingCollectionOffset!,
typeof(object)),
collectionShaperExpression.InnerShaper,
collectionShaperExpression.Navigation,
@@ -2126,7 +2133,7 @@ private ProjectionBindingExpression Remap(ProjectionBindingExpression projection
}
var indexMap = new Dictionary();
- foreach (var item in projectionBindingExpression.IndexMap)
+ foreach (var item in projectionBindingExpression.IndexMap!)
{
indexMap[item.Key] = _indexMap[item.Value];
}
@@ -2135,7 +2142,7 @@ private ProjectionBindingExpression Remap(ProjectionBindingExpression projection
}
var currentProjectionMember = projectionBindingExpression.ProjectionMember;
- var newBinding = _projectionMemberMappings[currentProjectionMember];
+ var newBinding = _projectionMemberMappings![currentProjectionMember!];
return CreateNewBinding(newBinding, projectionBindingExpression.Type);
}
@@ -2157,7 +2164,7 @@ private ProjectionBindingExpression CreateNewBinding(object binding, Type type)
private void AddJoin(
JoinType joinType,
ref SelectExpression innerSelectExpression,
- SqlExpression joinPredicate = null)
+ SqlExpression? joinPredicate = null)
{
// Try to convert Apply to normal join
if (joinType == JoinType.CrossApply
@@ -2200,7 +2207,7 @@ private void AddJoin(
: new[] { new OrderingExpression(new SqlFragmentExpression("(SELECT 1)"), true) };
var rowNumberExpression = new RowNumberExpression(
- partitions, orderings.ToList(), (limit ?? offset).TypeMapping);
+ partitions, orderings.ToList(), (limit ?? offset)!.TypeMapping);
innerSelectExpression.ClearOrdering();
var projectionMappings = innerSelectExpression.PushdownIntoSubquery();
@@ -2209,8 +2216,8 @@ private void AddJoin(
joinPredicate = new SqlRemappingVisitor(projectionMappings, subquery).Remap(joinPredicate);
var outerColumn = subquery.GenerateOuterColumn(rowNumberExpression, "row");
- SqlExpression offsetPredicate = null;
- SqlExpression limitPredicate = null;
+ SqlExpression? offsetPredicate = null;
+ SqlExpression? limitPredicate = null;
if (offset != null)
{
offsetPredicate = new SqlBinaryExpression(
@@ -2239,7 +2246,7 @@ private void AddJoin(
ExpressionType.AndAlso, offsetPredicate, limitPredicate, typeof(bool), joinPredicate.TypeMapping)
: offsetPredicate
: limitPredicate;
- innerSelectExpression.ApplyPredicate(predicate);
+ innerSelectExpression.ApplyPredicate(predicate!);
}
joinType = joinType == JoinType.CrossApply ? JoinType.InnerJoin : JoinType.LeftJoin;
@@ -2311,8 +2318,8 @@ private void AddJoin(
var joinTable = joinType switch
{
- JoinType.InnerJoin => new InnerJoinExpression(innerTable, joinPredicate),
- JoinType.LeftJoin => new LeftJoinExpression(innerTable, joinPredicate),
+ JoinType.InnerJoin => new InnerJoinExpression(innerTable, joinPredicate!),
+ JoinType.LeftJoin => new LeftJoinExpression(innerTable, joinPredicate!),
JoinType.CrossJoin => new CrossJoinExpression(innerTable),
JoinType.CrossApply => new CrossApplyExpression(innerTable),
JoinType.OuterApply => (TableExpressionBase)new OuterApplyExpression(innerTable),
@@ -2481,13 +2488,16 @@ public SqlRemappingVisitor(IDictionary mappings
_mappings = mappings;
}
- public SqlExpression Remap(SqlExpression sqlExpression)
- => (SqlExpression)Visit(sqlExpression);
+ [return: CA.NotNullIfNotNull("sqlExpression")]
+ public SqlExpression? Remap(SqlExpression? sqlExpression)
+ => (SqlExpression?)Visit(sqlExpression);
- public SelectExpression Remap(SelectExpression sqlExpression)
- => (SelectExpression)Visit(sqlExpression);
+ [return: CA.NotNullIfNotNull("sqlExpression")]
+ public SelectExpression? Remap(SelectExpression? sqlExpression)
+ => (SelectExpression?)Visit(sqlExpression);
- public override Expression Visit(Expression expression)
+ [return: CA.NotNullIfNotNull("expression")]
+ public override Expression? Visit(Expression? expression)
{
switch (expression)
{
@@ -2514,7 +2524,7 @@ private void AddJoin(
JoinType joinType,
SelectExpression innerSelectExpression,
Type transparentIdentifierType,
- SqlExpression joinPredicate)
+ SqlExpression? joinPredicate)
{
AddJoin(joinType, ref innerSelectExpression, joinPredicate);
@@ -2638,7 +2648,7 @@ public void AddOuterApply([NotNull] SelectExpression innerSelectExpression, [Can
public SelectExpression Prune()
=> Prune(referencedColumns: null);
- private SelectExpression Prune(IReadOnlyCollection