ManyToMany join entity type with separate PK results in incorrect FK configuration #26814
Labels
area-model-building
customer-reported
punted-for-7.0
Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints.
type-bug
Milestone
When configuring a many-to-many relationship, if we define the key of the skipped entity separately, the related collection entities stop appearing in the loaded collection, despite being loaded into the change tracker and having the correct keys in database.
Even though this bug is caused by mis-configuration, it is not reported as an error, and causes a confusing situation.
Full fiddle here: https://dotnetfiddle.net/TI9G5V
For this correct & working code snippet:
the bug is caused by changing it to this:
now EF won't load Blog.Posts, despite loading the Posts into the Change tracker. It seems EF does not consider the entities related despite loading them in the filtered query.
This happened because i set all entity primary keys first in OnModelCreating, then add properties and relations as needed. It would be nice to have an error at model build time, instead of strange behavior at query time.
Include provider and version information
EF Core version: 6.0.0
Database provider: InMemory
Target framework: .NET 6.0
The text was updated successfully, but these errors were encountered: