-
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
Issue with dynamic 'OrderBy' and AutoMapper inherited types #18584
Comments
|
@smitpatel Both expressions are the same, I verified the expression tree |
In the memberExpression |
@smitpatel So since this code worked flawlessly for years in EntityFramework, what is it, in practical terms, about EF Core that doesnt like this code |
// Form1
new ClassroomViewModel {
Classroom = c.Name,
NumStudents = s.Students.Count()
}.NumStudents
// Form2
s.Students.Count() In order for us to convert Form1 to form2, the MemberInfo inside ClassroomViewModel NumStudents must match MemberInfo used in MemberExpression. In your dynamically generated case they are different so we cannot simplify it. So you get error. Given compiler does not generate that kind of expression tree, it is low priority for us to try to support such scenarios. |
|
@smitpatel thanks, I must be blind :) If anyone is interested, I've updated the GIST with the working 'ObjectQueryExtensions.cs' |
I also run into this trouble , constructing a dynamic expression is critical to our product. For example, we let user only write basic select query, and we add orderby expression dynamically when he click a list title. If you are not going to fix this, please at least tell me a walk around. |
@onionhammer hi, have you solved this problem? |
@liuliang-wt - See #18386 (comment) |
@liuliang-wt Take a look at this: https://gist.github.com/onionhammer/5137cefeface774af96af905a76593b6 |
We are enabling support for this scenario in #19182 |
Similar description to #11453, but with EF Core 3.1 preview;
If I generate an 'OrderBy' using a dynamic expression, I receive an 'InvalidOperationException',
"...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 "
If I use the equivalent non-generated code, the query executes fine.
OrderByExpression()
is defined here, and works for simple cases, but when combined withSteps to reproduce
Further technical details
EF Core version:
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET Core 3.0)
Operating system:
IDE: (e.g. Visual Studio 2019 16.3)
The text was updated successfully, but these errors were encountered: