-
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 ORDER BY clause is generated for query with projection that includes foreign key property #12551
Comments
Thanks. I tried that, but, it gave the same results.
Jon
From: Igo Ventura <[email protected]>
Sent: Wednesday, July 4, 2018 12:54 PM
To: aspnet/EntityFrameworkCore <[email protected]>
Cc: Jon Miller <[email protected]>; Author <[email protected]>
Subject: Re: [aspnet/EntityFrameworkCore] Invalid ORDER BY clause is generated for query with projection that includes foreign key property (#12551)
I think that the error is at the OrderBy in linq:
var q = from e2 in oleContext.Encumbrances
// .OrderBy(e2 => e2.OriginCode) causes error
.OrderBy(e2 => e2.Origin.Code) // try this
select new
{
//Origin1 = e2.OriginCode,
Origin1 = e2.Origin.Code,
e2.OriginCode,
};
I think it's missing the dot. ASAP i'll test the project in the issue description and check.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#12551 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/APMZ5fRRvyRq_IOaFwQzkrYJmcZP_kYhks5uDQFPgaJpZM4VC2kV>.
|
@smitpatel to de-dupe. |
Duplicate of #12180 |
Added regression test in 956f339 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following query fails with EF Core 2.1.1 with following exception.
When using EF Core 2.0.2, the query works fine and produces the following SQL.
I tested with the SQL Server, PostgreSQL, and Pomelo MySQL providers and the behavior is the same for all of them. Also, I tested on .NET Framework and .NET Core.
The problem looks like it has something to do with the fact that the query is doing a projection and is including the same foreign key value more than once. The above example is for a query that isolates and demonstrates the problem. The reason I am selecting the value like that twice is that I have a scaffolding generator application that I developed which generates web pages with grids. The generator generates the queries so that only the needed fields are selected. It includes foreign key values so that hyperlinks can be generated that link to the referenced objects. The hyperlink text is set to the DisplayColumn for the referenced entity. In some cases the DisplayColumn happens to be the foreign key in the referenced table. I just wanted to give some background as to why I am doing that. This has always worked with previous versions of EF Core and EF. I found that the behavior is the same whether the foreign key property in the referencing entity is used or the primary key property in the referenced entity is used. I am assuming that EF Core is eliminating the duplicates from the SQL query, but, it is not quite right with regard to the ORDER BY clause.
EF Core version: 2.1.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer 2.1.1, Npgsql.EntityFrameworkCore.PostgreSQL 2.1.1, Pomelo.EntityFrameworkCore.MySql 2.1.0-rc2-final
Operating system: Windows 10
IDE: Visual Studio 2017 15.7.4
The following file contains a project that demonstrates the problem.
Ole7201807041149.zip
The text was updated successfully, but these errors were encountered: