How do Entity Framework Code-First transformations reflect domain-driven design?

I want to use the Entity Framework Code - first for a new project. So I decided to do some research and build a demo so that I could see how this is done. Through, I have a serious problem, or probably more than what I don’t understand, due to how the Framework code-first entity maps the entities and the domain-driven design.

As you create the application, we define domain objects. (we determine the roots of aggregates and create repositories for them depending on the business situation on what ive heard)

This is good, but the Entity Framework Code-First seems to work like a relational path between objects. So how can both coexist?

As an example ("Thinking on the side managed by the domain"):

The journal contains JournalEnty contains tasks, problems, notes

Cursive words are entities. In some ways, after the analysis, I would say that the journal is the combined root of the aggregate journal and journalist, since it is a direct composition. Each task contains the value of the hour to find out how many hours were spent on tasks, so there are many ways to calculate the total number of hours, as well as the salary that comes from it. The magazine has the property of an hourly rate.

Other entities are the aggregate root, and they may have a link to the journalist so that we know where the tasks, notes, and problems are.

But the problem is here ... how can Entity Framework Code-First mapping reflect this? From an intuitive point of view, we would say that a journal contains a journal entry and that a journal entry contains notes, problems and tasks. But from the point of view of DDD, this is probably not the case. Correct me if I am wrong, but first work with the code as a relational database.

So, how could we match the example above at the beginning of the code?

Thanks a lot.

+7
source share
1 answer


I think it’s nice if every domain object has a corresponding table in the database. And this does not mean that it is a relational structure, because the Journal object has the JournalEntity property (in the relational structure, the Entity journal has only JournalID). In addition, you can map a hierarchy of objects to a single table and create complex types in your mappings. This means that you can have more complex matching scripts, and then a class for the table.

Here is a ScottGu blog post about this.

+2
source

All Articles