-
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
InvalidOperationException when using dynamically created expressions with projections to derived types #18386
Comments
Your issue is bad reflection.
MemberInfo for Further, when I write the order by manually, var usersQueryable = context.Users
.Select(u => new User
{
Name = u.Name
})
.OrderBy(v => v.Name) The MemberInfo for both |
Thank you very much, I've been able to locate the error and fix the issue! |
Can you please share your solution? |
Hey @onionhammer, here's the relevant commit from LightQuery: GeorgDangl/LightQuery@5343116#diff-29ac354021182e6dbc1a86496f11807f |
We are enabling support for this scenario in #19182 |
In LightQuery, I'm dynamically creating expressions for sorting (
OrderBy
andOrderByDescending
)ObjectResult
s in ASP.NET Core where theValue
is aIQueryable
. It's basically an attribute that applies sorting and pagination parameters from the Http request to the results.With
netcoreapp3.0
and Entity Framework Core 3.0.0, a regression was reported for a specific use case: When theIQueryable
has a projection to a derived class, anInvalidOperationException
is thrown.Below is a complete repro, it's been verified both with SQLite and SQL Server. InMemory works fine. Additionally, there's a project from @binard available that demonstrates the issue in action: https://github.com/binard/testlq
Steps to reproduce
The below sample demonstrates the issue with
Microsoft.EntityFrameworkCore.Sqlite
version3.0.0
. The code works fine with earlier versions, e.g.2.1.3
.ExpressionTest.cs
Here's the complete stacktrace of the xUnit test:
I'd be very happy to hear about any possible workarounds😊
Further technical details
EF Core version: 3.0.0
Database provider: Microsoft.EntityFrameworkCore.Sqlite
Target framework: .NET Core 3.0
Operating system: Current Windows 10
IDE: Visual Studio 2019 16.3.4
The text was updated successfully, but these errors were encountered: