DEV Community

Discussion on: [Best practice] C# 9 Records as DDD Value Objects with EF Core 6

Collapse
 
brokenthorn profile image
Paul-Sebastian Manole

I thought owned types were already implement by EFCore as fields of the owner.
Why are you overriding that and creating a separate table?
By default, you wouldn't need so much customization code.
For example, EFCore would have created the fields Person.Address_Street_City_Name, Person.Street_City_State_Country_Initials, Person.Street_Street_City_State_Country_Name, and so on, without requiring a join and a separate table, and foreign keys, etc.

That should be faster to query and btw, EFCore takes care of creating the shadow identities behind the scenes in this case, and you don't need to worry about them, because you don't need them, they're just there so that EFCore can keep track of the object to database mapping.

Collapse
 
antoniofalcaojr profile image
Antonio Falcão Jr.

Hi @brokenthorn , thanks for the comment!

It's a trade-off between "JOIN" and "Let the table grow as the number of value objects grows".

In this case, I think those depend on the context.

Collapse
 
marchy profile image
Marcel Bradea

Remember tables are for computers not humans.

You should do what is most performant not what is "easiest to read".
Your context hasn't been stated – but in general for databases optimize for the machine, not the human. That's what OO is for.