Skip to content
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

Projection with dependent creates extra fields in SQL SELECT statement #9082

Closed
BenjiZombie opened this issue Jul 6, 2017 · 2 comments
Closed

Comments

@BenjiZombie
Copy link

Hi,

Using the following code, I was expecting to see a more concise SQL query that includes only the projected fields, but instead the SQL query includes all fields:

var customer = _customers
	.AsNoTracking()
	.Select(e => new { e.Id, e.Referral, e.State, e.HomeAddress.City })
	.ToList();
info: Microsoft.EntityFrameworkCore.Storage.IRelationalCommandBuilderFactory[1]
      Executed DbCommand (6ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT "e"."Id", "e"."CreatedBy", "e"."CreatedOn", "e"."Referral", "e"."RowVersion", "e"."State", "e"."UpdatedBy", "e"."UpdatedOn", "e.HomeAddress"."Id", "e.HomeAddress"."BillingAddressCustomerId", "e.HomeAddress"."City", "e.HomeAddress"."Country", "e.HomeAddress"."FormattedAddress", "e.HomeAddress"."HomeAddressCustomerId", "e.HomeAddress"."PostalCode", "e.HomeAddress"."Province", "e.HomeAddress"."StreetLine1", "e.HomeAddress"."StreetLine2"
      FROM "Application"."Customers" AS "e"
      LEFT JOIN "Application"."CustomerAddresses" AS "e.HomeAddress" ON "e"."Id" = "e.HomeAddress"."HomeAddressCustomerId"
      ORDER BY "e"."Id"

As you can guess, the Customer entity has a child HomeAddress entity navigation (one-to-one). If I omit the e.HomeAddress.City from the projection, the resulting SQL query is correct (as in, it only includes the Id, Referral and State fields in the SELECT statement).

Are my expectations incorrect?

Thanks

Further technical details

EF Core version: 1.1.2
Database Provider: NpgSql
Operating system: Windows 10
IDE: Visual Studio 2017

@smitpatel
Copy link
Contributor

dupe of #6647
Can you try with 2.0.0-preview1 (or preview2) package?

@BenjiZombie
Copy link
Author

Unfortunately I cannot.

Thanks for the reference to the similar issue, I will try to work something out or wait for final 2.0.

Regards

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants