-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
No translation for IEnumerable<int>.AsQueryable() as source for Contains query #22881
Comments
this was working and its not now, Ef core 5, I am sure this was working in a version of 3.1,
this does not work either
to be clear the rest looks like
if i comment out the searchString block it works. but then its not doing it, used to work. changing to something like
did give fruit tho |
@Seabizkit - It was not working in EF Core 3.1 either if searchstring is non-empty. See #19070. Your query is not related to this issue. |
@ajcvickers friendly bump - would this be considered a candidate to move from backlog anytime soon? |
@joakimriedel This issue has no votes. I don't see us working on this any time soon. |
Ok thanks I'll see if I can do something about it myself. |
Background
I would like to be able to write a query that sometimes uses a list of IDs directly queried from the database, and sometimes uses a hard coded list of IDs, based on a condition. The hard coded list is cast to
IQueryable<int>
usingAsQueryable()
to be able to send it as a parameter to a method which accepts anIQueryable<int>
Something like this trivial example, but in real life obviously the queries are more complex.
This query executes successfully if condition is
false
, but throws a runtime exception (see below) if condition istrue
- not being able to translate the expression.Workaround
By adding AsEnumerable() in the query, it works for both conditions and still executes fully server side.
SQL output for condition = true
WHERE [o].[Id] = 1
SQL output for condition = false (EF Core 3.1.8)
SQL output for condition = false (EF Core 5.0 RC1)
Seems to work like a charm for both condition values! 👍
Bug/feature request/question
Is this a bug or feature request? Not sure, but I would be happy to be able to do this without the workaround since it's easy to forget when building queries potentially causing the application to crash during runtime based on the actual underlying type of the
IQueryable<int>
. It does not seem to be a regression in 5.0 rc1, have tested this code (without workaround) as far back as 2.1.If this already supported somehow but I am missing something obvious here - then please accept this as a question.
Stack trace
EF Core version: 5.0 rc1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
edit: the first post had a stupid workaround, it's AsEnumerable() that makes it work since IQueryable will always test true for IEnumerable...
The text was updated successfully, but these errors were encountered: