diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs index 50528bb17a4..59d29ff0ded 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs @@ -609,7 +609,7 @@ protected override Expression VisitExtension(Expression extensionExpression) protected override Expression VisitParameter(ParameterExpression parameterExpression) { - if (parameterExpression.Name.StartsWith(CompiledQueryParameterPrefix, StringComparison.Ordinal)) + if (parameterExpression.Name?.StartsWith(CompiledQueryParameterPrefix, StringComparison.Ordinal) == true) { return Expression.Call( _getParameterValueMethodInfo.MakeGenericMethod(parameterExpression.Type), diff --git a/src/EFCore/Query/Internal/EntityEqualityRewritingExpressionVisitor.cs b/src/EFCore/Query/Internal/EntityEqualityRewritingExpressionVisitor.cs index a8625507780..1753f5f214a 100644 --- a/src/EFCore/Query/Internal/EntityEqualityRewritingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/EntityEqualityRewritingExpressionVisitor.cs @@ -430,7 +430,7 @@ private Expression VisitContainsMethodCall(MethodCallExpression methodCallExpres rewrittenSource = Expression.Constant(keyList, keyListType); } else if (newSource is ParameterExpression listParam - && listParam.Name.StartsWith(CompiledQueryCache.CompiledQueryParameterPrefix, StringComparison.Ordinal)) + && listParam.Name?.StartsWith(CompiledQueryCache.CompiledQueryParameterPrefix, StringComparison.Ordinal) == true) { // The source list is a parameter. Add a runtime parameter that will contain a list of the extracted keys for each execution. var lambda = Expression.Lambda( @@ -938,7 +938,7 @@ private Expression CreatePropertyAccessExpression(Expression target, IProperty p // If the target is a query parameter, we can't simply add a property access over it, but must instead cause a new // parameter to be added at runtime, with the value of the property on the base parameter. if (target is ParameterExpression baseParameterExpression - && baseParameterExpression.Name.StartsWith(CompiledQueryCache.CompiledQueryParameterPrefix, StringComparison.Ordinal)) + && baseParameterExpression.Name?.StartsWith(CompiledQueryCache.CompiledQueryParameterPrefix, StringComparison.Ordinal) == true) { // Generate an expression to get the base parameter from the query context's parameter list, and extract the // property from that