Closed andleer closed 3 years ago
I've already investigated this to some extent, will soon paste a simplified repro on what is likely a bug.
The issue here seems to be that inserting a M2M join entity (PlayerGame) referencing new instances (Playere, Game) does not cause the navigation properties on the instances to be populated. In contrast, when inserting a Player with a Game in its Games list, the Game's Players list is populated.
@andleer as a workaround, you can reload the Player/Game from the database (see the use ChangerTracker.Clear below).
I agree with your assessment. Sorry I didn't spell that out before but it is pretty simple and I already have been using that as a workaround.
But are you confirming it is a bug or possible future functionality? We're a little into the world of esoteric at this point so it doesn't matter much either way. I am good and appreciate the feedback.
@andleer I think so, but let's let @AndriySvyryd confirm.
I don't know if this is a bug or am I missing something?
Two simple entities that are connected with a simple mapping table that contains a single payload item. Both (non-mapping) entities contain a collection of the opposing entity and a collection of the common mapping entity. If I add one of the non-mapping entities to the other's collection and attach the "base" entity to the context, the context mapping dbset is correctly populated but I am unable to default the mapping entity's payload in code or via fluent config.
I have tried populating the mapping entity along with the payload value and adding that to the context dbset and saving changes on the entity but the simple many to many collections on the non-mapping entities are not populated.
Seems like a catch 22.
Repo with tests: https://github.com/andleer/BinaryOcean.EFCore5
EF Core version: 5.0.1 Database provider: Microsoft.EntityFrameworkCore.InMemory (5.0.1) Target framework: .NET 5.0 Operating system: Win10 IDE: Microsoft Visual Studio Community 2019 Version 16.8.3