Cannot translate Contains for simple string comparison (not a collection)
See original GitHub issueAfter upgrading to 3.0 method using Where with string.Contains(string) inside throws translation error.
Steps to reproduce
Context.Entity.Where(x => x.Value.ToLower().Contains(searchFilter))
.AsQueryable();
x is an object with properties int Id and string Value. searchFilter is a simple string.
Exception similiar to the issue when Contains is called on Collections (saw this issue already reported):
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()
Of course it was working fine before upgrading to 3.0. So is there a way to write it as translateable to SQL or do I have to call the query without this filter and then filter it locally?
Further technical details
EF Core version: 3.0 Database provider: Microsoft.EntityFrameworkCore.SqlServer (MSSQL 2016) Target framework: .NET Core 3.0 Operating system: IDE: Visual Studio 2019 16.3.7
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (7 by maintainers)
@MichalLechowski as we made changes in this area (#18486), can you please try with 3.1.0-preview2 and report the results?
Regardless, I couldn’t repro the issue on 3.0 with the following code. If your issue persists with 3.1.0-preview2, could you please submit a full repro such as the following?
This produces the following SQL (again on 3.0):
EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.
BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we’d like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.