Open Synergia503 opened 3 years ago
I haven't tried this with EF Core. Try to configure each value object separately, it might work this way: https://docs.microsoft.com/en-us/ef/core/modeling/owned-entities#nested-owned-types
Regarding the domain model itself -- it looks good, except for one thing. Looks like some of the VOs are interdependent. It's best to represent them as enumerations where you hard-code the dependency instead of allowing the clients to manually tie one VO to another. Here's an example from my recent project: https://gist.github.com/vkhorikov/8b966da515928a6f96f2d7fa28bcd72f In your case, the inheriting VOs will return other VOs instead of primitive types like in my case.
Converting some VOs into entities may also help to work around these issues, but try the above link first.
And of course, an obligatory reference: NHibernate doesn't have any of these issues and supports nested VOs with no issues.
Hi Vladimir! Thanks for your course, it's really great with amazing knowledge! I would like to ask you about a quite complex (IMO) case. Let's say I have a bunch of Value Objects (I removed some of the nested VOs and I removed business logic from all of them as well to make things clear):
How could I model this structure of VOs for EF Core DbContext in OnModelCreating() methods? I tried several things and I had been only getting errors like this: https://stackoverflow.com/questions/54328216/ef-core-modelbuilder-not-a-valid-expression-fluent-api but of course my error was not exactly like this and the answer from this link is not the solution for me. I mean, I've just got an exception similar to "The expression 'a => a.xyz' is not a valid property expression. The expression should represent simple property access: 't => t.MyProperty'.". I see of course this extract: "simple property access" thus my question here, because I have a complex structure of VOs with more nested VOs which equals in the end in more than simple property access requirements. Have you ever designed such a complex and deep structure of VOs? With EF Core, am I only able to have one level of nested VOs?
To make thing more generic, this kind of structure does not work for me with EF Core Fluent API:
OR it could work, it can be modeled but I just don't know how to properly use OwnsOne() methods and other methods from EF Core Fluent API? Do you know how one can solve this kind of complex structure with more levels of nested VOs and Entities? Maybe am I doing something wrong in Domain Modeling, like there should be more Entities instead of VOs? For my non-generic example, VOs: AreaUnit, DecimalValue, DecimalSeparator (and more nested VOs with more nested VOs, etc.) have to be Entities (or at least some of them)? The problem is they are not Entities in my Domain, but maybe to workaround EF Core, they should be Entities? Or maybe I have to disentangle nested VOs and move them up? But then, I would end up with a class with about 1000 lines - so much logic I have inside all the nested VOs. Hopefully, I've presented my issue clearly, if not, I'll try to give more clues, just let me know. Thank you very very much in advance!