Reputation: 41
Using EF Core 5 and the ABP framework I have an entity of type System
which has a owned type Property
. Property
itself is not an entity cause it has no identifier, just a value and a default value property:
public class System : AuditedEntity<Guid>
{
public Property<string> Setting { get; set; }
}
public Property<T>
{
public T Value { get; set; }
public T DefaultValue { get; set; }
}
The configuration for the entity looks like this simply:
modelBuilder.Entity<System>(b =>
{
b.OwnsOne(p => p.Setting);
}
When I now load a System and update one of the properties of the Property
object inside and then check the EF Core's changes by looking into the ChangeTracker, I see that EF Core tells me there is something "Added", not "Modified".
The Debug view in ChangeTracker shows this in the LongView:
System.Setting#Property<string> (Shared) {SystemId: 92f7a6a3-3453-4fd7-45db-08d972bde903} Added
SystemId: '92f7a6a3-3453-4fd7-45db-08d972bde903' PK FK
DefaultValue: ''
Value: 'new value'
Why does it say "Added" and not "Modified"? Because it is not an entity itself? Can I change my configuration to have this visible as a change on the parent (System
marked as "Modified") since I expect Value
and DefaultValue
to be special (=owned) properties of the parent?
The issue is in the end that I cannot handle changes on such owned inner objects the same way like changes on "normal" properties. Is there a best practise for such owned types somewhere?
Upvotes: 4
Views: 688