Skip to content

Commit

Permalink
Fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
cincuranet committed Dec 2, 2024
1 parent 0cd92f7 commit e483357
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,16 @@ private Expression TryConvertCollectionContainsToQueryableContains(MethodCallExp

var sourceType = methodCallExpression.Method.DeclaringType!.GetGenericArguments()[0];

var objectExpression = methodCallExpression.Object!.Type.IsValueType
? Expression.Convert(methodCallExpression.Object!, typeof(IEnumerable<>).MakeGenericType(sourceType))
: methodCallExpression.Object!;

return VisitMethodCall(
Expression.Call(
QueryableMethods.Contains.MakeGenericMethod(sourceType),
Expression.Call(
QueryableMethods.AsQueryable.MakeGenericMethod(sourceType),
methodCallExpression.Object!),
objectExpression),
methodCallExpression.Arguments[0]));
}

Expand Down
8 changes: 7 additions & 1 deletion src/EFCore/Query/QueryRootProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp

private Expression VisitQueryRootCandidate(Expression expression, Type elementClrType)
{
switch (expression)
var candidateExpression = expression;
if (expression is UnaryExpression { NodeType: ExpressionType.Convert } convertExpression
&& convertExpression.Type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
{
candidateExpression = convertExpression.Operand;
}
switch (candidateExpression)
{
// An array containing only constants is represented as a ConstantExpression with the array as the value.
// Convert that into a NewArrayExpression for use with InlineQueryRootExpression
Expand Down

0 comments on commit e483357

Please sign in to comment.