Skip to content

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

Closed

Description

@steffibreuer

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

Activity

  1. self-assigned this
    on Apr 14, 2020
  2. added 2 commits that reference this issue on Apr 14, 2020
    98a95e3
    94eb476
  3. added a commit that references this issue on Apr 14, 2020
    2ffa15d
  4. added this to the 5.0.0 milestone on Apr 14, 2020
  5. modified the milestones: 5.0.0, on Apr 20, 2020
  6. modified the milestones: , 5.0.0 on Nov 7, 2020
  7. LouLeGrain commented on Jun 7, 2024

    @LouLeGrain

    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.

  8. ajcvickers commented on Jun 7, 2024

    @ajcvickers
    Contributor

    @LouLeGrain I filed #33928 to track this.

  9. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions