-
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
CosmosDB - Entity Framework Core - Contains could not be translated #18673
Comments
|
Note from triage: do the 3.1 relational fix for Cosmos. |
Any further info on this? I'm encountering the same error in .NET Core 3.1. @ajcvickers What is the relational fix you mentioned? var user = await Context.Users.Where(x => x.email.Contains("string")).FirstOrDefaultAsync(); System.InvalidOperationException |
I'm also seeing this error in 3.1 |
Still an issue in 3.1.1.. It looks like the solution has been merged though, so when can we expect it to be released? |
@AndriySvyryd @smitpatel Difference between #16143 and this issue? |
This is a subset. |
I try to manipulate a CosmosDB (SQL) using entity framework core 3.0. Everything works fine except when I try to use Contains
For example:
var query = _context.Challenges.Where(c => c.Name.Contains( "string"));
EF is supposed to translate it to the following SQL (that works perfectly on the CosmosDB – Query Explorer)
SELECT * FROM c WHERE CONTAINS(c.Name, "string")
But I receive the following error message:
The LINQ expression 'Where(\n source: DbSet, \n predicate: (c) => c.Name.Contains("string"))' 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.
Of course, I don’t want to code it like the following, that will execute the entire contains on the client, just to make a simple LIKE…
List entities = _context.Challenges.AsEnumerable().Where(c => c.Name.Contains( "string")).ToList();
Any idea of to evaluate the "contains" on the server side ?
Note: I try the exact same code using UseSqlServer rather than UseCosmos (and by adding the needed [Key] annotation and creating a SQL server) and it works like a charm.... So I think it's a definitively a CosmosDB vs EF issue.
EF Core version:
Database provider: Microsoft.EntityFrameworkCore.Cosmos
Target framework: NET Core 3.0.0
Operating system: OS X Windows 10 (try both)
IDE: Last stable version on both OSX and Windows 10
Thanks in advance for your help.
The text was updated successfully, but these errors were encountered: