I wrote this in a Github issue thread about EFCore & lack of current support for complex types (which support DDD Value Objects .. to a degree) this morning and someone said I should share it so here it is:
I love value objects. I’m just not considering efcore for any serious work yet so I am not going to stress out about not using them. I find myself designing my domain with them out of habit then having to undo. And if you are set on efcore, then +++ to @jnm2 ‘s point. I map from domain to EF’s data model (the in-memory model that EF infers at runtime) using EF’s mapping when it’s easy and I don’t have to make annoying (or worse) concessions. Otherwise it is time for a mapper between domain and data model defined by separate classes + EF DBContext. So EF mapping layer is my default mapper when using EF. But sometimes it is just not sufficient and I go to (or recommend) the effort of building a separate data model. Your choice. Pick your battles.
Another point is that Jimmy Bogard doesn’t even think the ef6 complex types do enough to map types that you’ve defined as value objects. So he’s been either just using one to one or going the extra mapper route depending on the situation. Gogglebing Jimmy Bogard, something like “what’s missing in ef6 for DDD” to read more. And then there’s that collection conundrum, too as well as the problem of mapping private fields. So if you are okay without those in EF6, maybe support for value objects isn’t such a huge deal except for the problem of it being “taken away” temporarily.
My ref to Jimmy Bogard was for his Domain modeling with Entity Framework scorecard post.
I’m sharing because of the following reply from Joseph Musser on this thread:
I would love to have had (and still would love) an article that thoroughly addresses that question: weighing the pros and cons of staying within EF modeling constraints or using a data model and mapping yourself. When to consider making the switch. And what that means for creating a rich, disciplined model that doesn’t become anemic. I feel like I’ve wasted a lot of time not having a fundamental understanding of this from the beginning.
Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!