Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List.Contains does not work with List<object> #20624

Closed
steffibreuer opened this issue Apr 14, 2020 · 2 comments · Fixed by #20628
Closed

List.Contains does not work with List<object> #20624

steffibreuer opened this issue Apr 14, 2020 · 2 comments · Fixed by #20628
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@steffibreuer
Copy link

Hello,

i'd like to create a query which filters by a List<object> in EFCore 3.1.3. This was working before in EFCore 2.2.6.

Steps to reproduce

Filtering by a List<object> throws an InvalidOperationException.

var itemIds = new List<object> { Guid.NewGuid() };
var items = await context.Item
    .Where(p => itemIds.Contains(p.ItemId))
    .ToListAsync();

System.InvalidOperationException: Null TypeMapping in Sql Tree
Stack Trace:
SqlTypeMappingVerifyingExpressionVisitor.VisitExtension(Expression node)
Expression.Accept(ExpressionVisitor visitor)
ExpressionVisitor.Visit(Expression node)
InExpression.VisitChildren(ExpressionVisitor visitor)
ExpressionVisitor.VisitExtension(Expression node)
SqlTypeMappingVerifyingExpressionVisitor.VisitExtension(Expression node)
Expression.Accept(ExpressionVisitor visitor)
ExpressionVisitor.Visit(Expression node)
RelationalSqlTranslatingExpressionVisitor.Translate(Expression expression)
RelationalQueryableMethodTranslatingExpressionVisitor.TranslateExpression(Expression expression)
RelationalQueryableMethodTranslatingExpressionVisitor.TranslateLambdaExpression(ShapedQueryExpression shapedQueryExpression, LambdaExpression lambdaExpression)
RelationalQueryableMethodTranslatingExpressionVisitor.TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate)
QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
MethodCallExpression.Accept(ExpressionVisitor visitor)
ExpressionVisitor.Visit(Expression node)
QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
Database.CompileQuery[TResult](Expression query, Boolean async)
QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
<>c__DisplayClass12_01.<ExecuteAsync>b__0() CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func1 compiler)
CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func1 compiler) QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken) EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken) EntityQueryable1.GetAsyncEnumerator(CancellationToken cancellationToken)
ConfiguredCancelableAsyncEnumerable1.GetAsyncEnumerator() EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken)

When i change the List type to Guid it works.
As this is only a simplified sample code changing the List type is not a prefereable option.

var referencedIds = new List<Guid> { Guid.NewGuid() };
var items = await context.Item
    .Where(p => itemIds.Contains(p.ItemId))
    .ToListAsync();

Further technical details

EF Core version: 3.1.3
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: netcoreapp3.1
Operating system: Windows 10
IDE: Visual Studio 2019 16.4

@smitpatel smitpatel self-assigned this Apr 14, 2020
@smitpatel smitpatel added type-bug closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels Apr 14, 2020
smitpatel added a commit that referenced this issue Apr 14, 2020
smitpatel added a commit that referenced this issue Apr 14, 2020
smitpatel added a commit that referenced this issue Apr 14, 2020
@smitpatel smitpatel added this to the 5.0.0 milestone Apr 14, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0, 5.0.0-preview4 Apr 20, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0-preview4, 5.0.0 Nov 7, 2020
@LouLeGrain
Copy link

Hello, i encountered the exact same error, in the same context with EF Core 8.0.6.

I made a small repo for reproduction here

We found a workaround to type the list we were using with reflection, but i thought I'll let you know.

@ajcvickers
Copy link
Member

@LouLeGrain I filed #33928 to track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants