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

CosmosDB - Entity Framework Core - Contains could not be translated #18673

Closed
patrickdgt opened this issue Oct 31, 2019 · 7 comments
Closed

CosmosDB - Entity Framework Core - Contains could not be translated #18673

patrickdgt opened this issue Oct 31, 2019 · 7 comments
Labels
area-cosmos area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Milestone

Comments

@patrickdgt
Copy link

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.

@smitpatel
Copy link
Member

smitpatel commented Oct 31, 2019

Duplicate of #16143

@smitpatel smitpatel marked this as a duplicate of #16143 Oct 31, 2019
@ajcvickers ajcvickers added this to the Backlog milestone Nov 1, 2019
@ajcvickers
Copy link
Member

Note from triage: do the 3.1 relational fix for Cosmos.

@ajcvickers ajcvickers marked this as not a duplicate of #16143 Nov 1, 2019
@krw1010
Copy link

krw1010 commented 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
Copy link

I'm also seeing this error in 3.1

@nickwilsonr
Copy link

nickwilsonr commented 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
Copy link
Member

@AndriySvyryd @smitpatel Difference between #16143 and this issue?

@AndriySvyryd
Copy link
Member

This is a subset.
Fixed in 83dccdc

@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jan 22, 2020
@AndriySvyryd AndriySvyryd modified the milestones: Backlog, 5.0.0 Jan 22, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0, 5.0.0-preview1 Mar 13, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0-preview1, 5.0.0 Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-cosmos area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Projects
None yet
Development

No branches or pull requests

7 participants