-
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
Substring with single parameter throws InvalidOperationException when adding Where clause #20173
Comments
In T-Sql, Hence we don't translate overload of substring with single parameter. You can rewrite the substring method call to have 2nd parameter like |
If you don't translate it, why this code works? var result = context.MyTable
.Select(a => new { Name = a.Name.Substring(1) })
.FirstOrDefault(); |
EF Core allows evaluating final projection on client side. |
Thank you for the clarification. In a real project, queries come to me from another module, and I just add filters to them. And I break them with that. Can I disable client side evaluation for final projections, to prevent this confusion? |
@xiety We're not planning to allow disabling client-evaluation in the final projection. It is general not the case that composing on an existing translatable query will always result in a translatable query, regardless of client-evaluation. |
I have a grid control with column filtering and it breaks some working queries only when user filters by specific column. I think such grid is a very common practice in business applications. |
Where can one find a list of all methods that are translatable and not translatable? Could you not translate the Substring without the length by calculating the length in the SQL? FWIW I came across this issue because there is an OData substring function which becomes the Substring method that can't be translated to SQL. |
You could perhaps do something like |
Moving this to the backlog as something we could translate, especially since it comes from OData. |
Fixes dotnet#20173
Steps to reproduce
Execute query:
See the exception:
Additinal information
Without
Where
theSelect
withSubstring(1)
works fineSubstring(1, 1)
with two parameters works fineFurther technical details
EF Core version: 3.1.2
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Full exception text
Source code
https://dotnetfiddle.net/QIWarC
The text was updated successfully, but these errors were encountered: