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

ICollection<T> doesn't translate to SQL #18639

Closed
jirkafajfr opened this issue Oct 29, 2019 · 1 comment
Closed

ICollection<T> doesn't translate to SQL #18639

jirkafajfr opened this issue Oct 29, 2019 · 1 comment

Comments

@jirkafajfr
Copy link

jirkafajfr commented Oct 29, 2019

When ICollection<T> is used in Where(...) it does not generate proper SQL query and crashes with request for query rewrite.

Steps to reproduce

I've created following repo https://github.com/jirkafajfr/EfCore-CollectionInExpressionProblem which demonstrates the problem. Essentially when ICollection<T> comes to the expression it can't be translated where array or list would work just fine.

Crashes

ICollection<int> ids = new List<int>
{
    1,
    2
};

_context.Blogs
    .Where(post => ids.Contains(post.BlogId))
    .Should()
    .NotBeEmpty();
System.InvalidOperationException : The LINQ expression 'Where<Blog>(
    source: DbSet<Blog>, 
    predicate: (b) => (Unhandled parameter: __ids_0).Contains(b.BlogId))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

Works fine

var ids = new List<int>
{
    1,
    2
};

_context.Blogs
    .Where(post => ids.Contains(post.BlogId))
    .Should()
    .NotBeEmpty();

Notes

The attached repo demonstrates that this used to work in EfCore 2.2 but is not broken with EfCore 3.0

Further technical details

EF Core version: 3.0
Database provider: Microsoft.EntityFrameworkCore.Sqlite, Npgsql.EntityFrameworkCore.PostgreSQL
Target framework: .NET Core 3.0
Operating system: Windows 10, Linux (attached docker)
IDE: Visual Studio 2019 16.3

@ajcvickers
Copy link
Contributor

Duplicate of #17342. Verified tests are passing with latest daily build.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants