❔ 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
Note: I am aware that I can just use LINQ. I want to know if there is a way to fix the FromSql approach.
2 Replies
Try aliasing?
"i"."CustomerId" as cuid
or some such
That said, why is the primary key of your Customer
even called CustomerId
in the first place?
Should just be Id
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.