From 5a1c2bd5df596e41c39e74372bf7ca1b1160b53c Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Fri, 3 Apr 2020 14:32:30 -0700 Subject: [PATCH] Check if parameter.Name is not null before comparing it with query parameter Resolves #20485 Parameters which are used inside lambda should get replaced with appropriate shaper/selector. All other parameters should be query parameters otherwise it is an error. --- .../InMemoryExpressionTranslatingExpressionVisitor.cs | 2 +- .../Internal/EntityEqualityRewritingExpressionVisitor.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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