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
{{ message }}
Repository navigation
Let me opt out from convention which treats Id property of an owned entity as a primary key. #35789
I am trying to map a collection of owned entities to json.
Owned entity has property Id and EF makes it an explicitly defined primary key, so I get the error:
'DbContext' of type ''. The exception 'Entity type 'FeatureId' is part of a collection mapped to JSON and has its ordinal key defined explicitly. Only implicitly defined ordinal keys are supported.'
I could not find a method in Fluent Api to explicitly tell EF that Id should be treated as a regular property.
I'd like to avoid the need to rename Id property to something else.
Describe the solution you'd like
Well, there should be away to set an annotation for the property: b.Property(e => e.Id).NotKey().
changed the title [-]Let me opt out from convention which treats Id property of an owned entity as primary key.[/-][+]Let me opt out from convention which treats Id property of an owned entity as a primary key.[/+]on Mar 14, 2025
You should be able to work around this by creating a different property to be used as the key:
modelBuilder.Entity<Customer>().OwnsOne(customer =>customer.Contact, b =>{b.ToJson();b.OwnsMany(e =>e.Features, b =>{b.Property<int>("Key").HasJsonPropertyName("Id");});});
Activity
[-]Let me opt out from convention which treats Id property of an owned entity as primary key.[/-][+]Let me opt out from convention which treats Id property of an owned entity as a primary key.[/+]AndriySvyryd commentedon Mar 20, 2025
You should be able to work around this by creating a different property to be used as the key:
The full fix is tracked in #28594