You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CosmosDB - Entity Framework Core - Contains could not be translated #18673
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.
Reacted by Alex Giovannetti , Rian Finnegan and Dave
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
HResult=0x80131509
Message=The LINQ expression 'DbSet
.Where(a => a.Email.Contains(__search_0))' 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.
Source=Microsoft.EntityFrameworkCore
Activity
smitpatel commentedon Oct 31, 2019
Duplicate of #16143ajcvickers commentedon Nov 1, 2019
Note from triage: do the 3.1 relational fix for Cosmos.
krw1010 commentedon Jan 10, 2020
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
HResult=0x80131509
Message=The LINQ expression 'DbSet
.Where(a => a.Email.Contains(__search_0))' 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.
Source=Microsoft.EntityFrameworkCore
xtellurian commentedon Jan 21, 2020
I'm also seeing this error in 3.1
nickwilsonr commentedon Jan 21, 2020
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?
ajcvickers commentedon Jan 22, 2020
@AndriySvyryd @smitpatel Difference between #16143 and this issue?
AndriySvyryd commentedon Jan 22, 2020
This is a subset.
Fixed in 83dccdc