-
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
Invalid column name: orderby uses a column alias that does not exist #12180
Comments
@mcorthout Do you know if this was working with 2.0 release? |
@ajcvickers - Its a regression from 2.0.2 |
@divega Looks like a reasonably common case--should we patch? @smitpatel Do you know if there is a workaround? |
It is slightly uncommon to include same property multiple times in the selector. (alongwith the same property being used in ordering which is necessary for bug to reproduce) var problem = from a in
(from item in context.Items
orderby item.Id, item.Name
select new { item.Id, item.Name }
).ToList()
select new SomeOtherObject
{
Id = a.Id,
SomeName = a.Name,
AnotherName = a.Name
}; It cause client eval for DTO part but it will not pull any additional data from server. In case of the DTO is inside subquery it is going to cause client eval anyway so above work-around does not worsen the query. |
…s-ing Issue: Since the projection has same property repeated twice in the DTO, we would add alias from member name. We match projection based on unwrapped alias but we don't do that in ordering. So we updated the projection but we did not update the ordering for new alias. Fix: Remember the removed projection and also use that while searching inside order by so we update ordering too and don't end up with incorrect column in order by list Resolves #12180
…s-ing Issue: Since the projection has same property repeated twice in the DTO, we would add alias from member name. We match projection based on unwrapped alias but we don't do that in ordering. So we updated the projection but we did not update the ordering for new alias. Fix: Remember the removed projection and also use that while searching inside order by so we update ordering too and don't end up with incorrect column in order by list Resolves #12180
Triage: after considering the fix, we think the risk is low enough that we can take this as a patch. |
I also had this issue. The workaround works, but keep in mind that this : context.Address.Select(a => new
{
a.ClientFk,
a.ClientFkNavigation.Id,
}); Will also throw the error because it is effectively the same property, even though it is not obvious at first glance. |
This is approved for 2.1.3. Do not merge yet; branch is expected to open Monday. Given these issues have been parked for some time, please be careful to ensure the correct commits get into the correct branches. |
@smitpatel This issue is approved for patch and the release\2.1 branch is now open for merging. Please ensure:
|
Under rather peculiar circumstances, orderby tries to use a column alias in the ORDER BY clause that is not present in the SELECT clause.
Exception:
Steps to reproduce
Expected result
Actual result
Further technical details
EF Core version: 2.1.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 7
IDE: Visual Studio 2017 15.7.2
The text was updated successfully, but these errors were encountered: