Entity that owns multiple entities of the same type with navigations back to the owning type makes model construction fail #35346
Labels
area-model-building
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
I have lots of entities for which I need to track when and by whom they were created and last updated. I have solved this by putting an owned type
UserTimestamp
on tracked entities asCreated
andUpdated
. Something like this:This worked well until I needed to add tracking to the
User
model, probably because of the self referencing that this introduces. If I putCreated
andUpdated
as above on theUser
model, EF throws during model construction.Below is a minimal reproduction:
which throws
However, if I remove the
Updated
property from the type and the configuration, the following model is created, which looks as expected:Everything also works if I make a copy of the class
UserTimestamp
and use that copy for theUpdated
property (so thatCreated
andUpdated
have nominally different, but otherwise equivalent, types).It seems to me that since it works to have navigations back to owning entity type for the case when the owning type owns a type once, and also when it owns multiple (nominally different) types, the expected behaviour is that is should also work for the case when it owns the same type multiple times.
Include provider and version information
EF Core version: 9.0.0
Database provider: occurs with both SQLServer and Postgres providers
Target framework: .NET 9.0
Operating system: N/A
IDE: N/A
The text was updated successfully, but these errors were encountered: