Skip to content

Commit

Permalink
Fix #7115 - DB query is executed with the parameters of the previous …
Browse files Browse the repository at this point in the history
…query

- Fixes an issue in ExpressionEqualityComparer where we would incorrectly determine equality for constant EnumerableQuery nodes.
  • Loading branch information
anpete committed Nov 28, 2016
1 parent a7e0117 commit 43c64d5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ public virtual void Local_array()
cs.Single(c => c.CustomerID == (string)context.Arguments["customerId"]));
}

[ConditionalFact]
public virtual void Method_with_constant_queryable_arg()
{
using (var context = CreateContext())
{
var count = QueryableArgQuery(context, new [] { "ALFKI" }.AsQueryable()).Count();

Assert.Equal(1, count);

count = QueryableArgQuery(context, new [] { "FOO" }.AsQueryable()).Count();

Assert.Equal(0, count);
}
}

private static IQueryable<Customer> QueryableArgQuery(NorthwindContext context, IQueryable<string> ids)
=> context.Customers.Where(c => ids.Contains(c.CustomerID));

[ConditionalFact]
public void Query_composition_against_ienumerable_set()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
}

if (declaringType == typeof(Queryable)
|| (declaringType == typeof(EntityFrameworkQueryableExtensions)
&& (!methodInfo.IsGenericMethod
|| methodInfo.GetGenericMethodDefinition() != EntityFrameworkQueryableExtensions.StringIncludeMethodInfo)))
|| declaringType == typeof(EntityFrameworkQueryableExtensions)
&& (!methodInfo.IsGenericMethod
|| methodInfo.GetGenericMethodDefinition() != EntityFrameworkQueryableExtensions.StringIncludeMethodInfo))
{
return base.VisitMethodCall(methodCallExpression);
}
Expand Down Expand Up @@ -261,8 +261,8 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
if (leftConstantExpression != null)
{
var constantValue = (bool)leftConstantExpression.Value;
if ((constantValue && binaryExpression.NodeType == ExpressionType.OrElse)
|| (!constantValue && binaryExpression.NodeType == ExpressionType.AndAlso))
if (constantValue && binaryExpression.NodeType == ExpressionType.OrElse
|| !constantValue && binaryExpression.NodeType == ExpressionType.AndAlso)
{
return newLeftExpression;
}
Expand All @@ -274,8 +274,8 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
if (rightConstantExpression != null)
{
var constantValue = (bool)rightConstantExpression.Value;
if ((constantValue && binaryExpression.NodeType == ExpressionType.OrElse)
|| (!constantValue && binaryExpression.NodeType == ExpressionType.AndAlso))
if (constantValue && binaryExpression.NodeType == ExpressionType.OrElse
|| !constantValue && binaryExpression.NodeType == ExpressionType.AndAlso)
{
return newRightExpression;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ private static bool CompareConstant(ConstantExpression a, ConstantExpression b)
return false;
}

if (a.Value is EnumerableQuery
&& b.Value is EnumerableQuery)
{
return false; // EnumerableQueries are opaque
}

if (a.Value is IQueryable
&& b.Value is IQueryable
&& a.Value.GetType() == b.Value.GetType())
Expand Down

0 comments on commit 43c64d5

Please sign in to comment.