-
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
Rownumber paging generates invalid SQL with DTO projection and orderby #9535
Comments
We probably need to unwrap AliasExpression. |
…owNumberPagingExpressionVisitor Issue: When converting OFFSET to RowNumber we move order by to projection. OrderBy allows refering to projection by their alias but in projection you cannot refer to another projection by its alias Solution: We need to unwrap the alias expression in order by when adding to projection so projection expression will print inner expression rather than the alias Resolves #9535
…owNumberPagingExpressionVisitor Issue: When converting OFFSET to RowNumber we move order by to projection. OrderBy allows refering to projection by their alias but in projection you cannot refer to another projection by its alias Solution: We need to unwrap the alias expression in order by when adding to projection so projection expression will print inner expression rather than the alias Resolves #9535
Triage: @smitpatel to document workarounds so we have more information for patch consideration. |
Work-around var test = await _users.OrderBy(i => i.Id)
.Select(i => new UserInfo
{
i.Id
}).Skip(0).Take(30).ToListAsync(); If the projection is non-member expression where assigning member name is mandatory, removing skip can help generating correct query but it may cause to fetch large data. Or other option is to do the custom projection on client. For example, var test = await _users
.Select(i => new UserInfo
{
DiscountedPrice = i.Price * i.Discount
})
.OrderBy(I => i.DiscountedPrice).Skip(0).Take(30).ToList();
// Work-arounds
// Remove skip
var test = await _users
.Select(i => new UserInfo
{
DiscountedPrice = i.Price * i.Discount
})
.OrderBy(I => i.DiscountedPrice).Take(30).ToList();
// Remove projection
var test = await _users
.OrderBy(I => i.Price * i.Discount).Skip(0).Take(30).AsEnumerable()
.Select(i => new UserInfo
{
DiscountedPrice = i.Price * i.Discount
}).ToList(); |
Triage: The workarounds and scope of the fix together with feedback are currently not such that this meets the bar for patch. |
Please what is the state of this issue? I am currently having similar issue. How do I resolve it? https://aspnetcore.slack.com/archives/C18UW3ALA/p1521474152000171 |
@smithaitufe This issue is fixed in the 2.1 preview1 release. So the options here are:
|
I find a bug ,if use
RowNumber
of paging:At this point, the orderby fields and select the fields can't be the same:
the translation of sql:
Error info :
the column name 'Id' is invalid
The text was updated successfully, but these errors were encountered: