You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I use AsNoTracking with IdentityResolution in combination with a projection in where a reference navigation property is also projected, then IdentityResolution doesn't work: Multiple principal instances will be created for entities having the same primary key.
If the referenced navigation property is NOT projected it works as expected.
Example
In my example (full working UnitTest see below) I've got an 'OrderPosition' containing a reference navigation 'Article'.
There're two order positions in database that each have a reference to the same (only) Article that exists.
This leads EFCore to create only one Article instance that is then referenced by both the positions (as expected):
Note for triage: in this case the query is explicitly creating instances of the principal entity, which means that we don't do identity resolution here for tracking queries either.
ajcvickers
changed the title
AsNoTracking with IdentityResolution doesn't work if a reference navigation is projected
Document that identity resolution does not apply to instances explicitly created with new
Feb 1, 2024
If I use AsNoTracking with IdentityResolution in combination with a projection in where a reference navigation property is also projected, then IdentityResolution doesn't work: Multiple principal instances will be created for entities having the same primary key.
If the referenced navigation property is NOT projected it works as expected.
Example
In my example (full working UnitTest see below) I've got an 'OrderPosition' containing a reference navigation 'Article'.
There're two order positions in database that each have a reference to the same (only) Article that exists.
This leads EFCore to create only one Article instance that is then referenced by both the positions (as expected):
But this leads EFCore to create TWO Article instances (what I think is wrong):
The complete example (UnitTest)
ProjectFile
Used provider and versions
EF Core version: 8.0.1
Database provider: Microsoft.EntityFrameworkCore.Sqlite | Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: Win 10.0.19044.3086]
IDE: Visual Studio 2022 17.8.4
The text was updated successfully, but these errors were encountered: