Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upSubstring 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. |


Steps to reproduce
Execute query:
See the exception:
Additinal information
Without
WheretheSelectwithSubstring(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