mantlefree
mantlefree
CC#
Created by mantlefree on 7/19/2023 in #help
Rider Early Access Program is it safe to use?
Do you recommend using Rider EAP version? https://www.jetbrains.com/rider/nextversion/
3 replies
CC#
Created by mantlefree on 4/4/2023 in #help
❔ EF Core 7 - FromSql join with same column names
This code produces ArgumentException -> An item with the same key has already been added. Key: CustomerId. Is there a way to fix this query? I know that I can remove the "i"."CustomerId" and it will work but imagine that Customer and Invoice entities have property with the same name this will cause the same error
Customers.FromSql($"""
SELECT "c"."CustomerId", "c"."Address", "c"."City", "c"."Company", "c"."Country", "c"."Email", "c"."Fax", "c"."FirstName", "c"."LastName", "c"."Phone", "c"."PostalCode", "c"."State", "c"."SupportRepId",
"i"."InvoiceId", "i"."BillingAddress", "i"."BillingCity", "i"."BillingCountry", "i"."BillingPostalCode", "i"."BillingState", "i"."CustomerId", "i"."InvoiceDate", "i"."Total"
FROM "Customer" AS "c"
LEFT JOIN "Invoice" AS "i" ON "c"."CustomerId" = "i"."CustomerId"
ORDER BY "c"."CustomerId"
""").AsNoTracking().ToList().Dump();
Customers.FromSql($"""
SELECT "c"."CustomerId", "c"."Address", "c"."City", "c"."Company", "c"."Country", "c"."Email", "c"."Fax", "c"."FirstName", "c"."LastName", "c"."Phone", "c"."PostalCode", "c"."State", "c"."SupportRepId",
"i"."InvoiceId", "i"."BillingAddress", "i"."BillingCity", "i"."BillingCountry", "i"."BillingPostalCode", "i"."BillingState", "i"."CustomerId", "i"."InvoiceDate", "i"."Total"
FROM "Customer" AS "c"
LEFT JOIN "Invoice" AS "i" ON "c"."CustomerId" = "i"."CustomerId"
ORDER BY "c"."CustomerId"
""").AsNoTracking().ToList().Dump();
Note: I am aware that I can just use LINQ. I want to know if there is a way to fix the FromSql approach.
Customers.Include(c => c.Invoices).Dump();
Customers.Include(c => c.Invoices).Dump();
6 replies