52737

DDD Database first . How to handle aggregates

I'm trying to learn the concept of DDD. I have made a project which i use the database first approach. In the infrastructure i have added an edmx file witch i have chosen to auto generate the entites. Now in the "Domain" I'm trying to create aggregates.

But here i got some problems. I´m trying to create a aggregate named "User" but User already exists in the entites that the ef autogenerated. Should i rename the aggregate "User" to something else and when getting data from the db map it from db entites to the aggregate.

I'm doing it wrong ? Or shouldn't i autogenerate the entities or is the enties aggregates ?

Plz advise and help.

<img src="https://i.stack.imgur.com/DXEz0.png" alt="enter image description here">

Answer1:

If you want to be true to DDD, you should model your domain objects to be independent of your persistence solution. DDD handles persistence through repositories. Don't use the "entities" generated by EF as your domain model; instead design your own model and implement a repository that makes use of EF for persistence.

Answer2:

From my point of view, Domain-Driven Design and "database first" are antithetic. Domain-Driven design focuses on complex behavior, and a data model focuses on the static structure of the data.

If I had the privilege to start from a clean situation, I wouldn't make it more complicated than necessary by creating a legacy database first. Consider that DDD is oriented to complex domain, where discovery and learning is part of the process.

To support a continuous learning process it's better to rely on software components which are more specifically designed for evolution (like an Object-Oriented Domain Model that can be under cheap Unit Tests) instead of a database design whose evolution is definitely more expensive.

Nobody can do everything right at the beginning. So I'd better start with something with a very little throwaway cost.

Recommend

  • Room API - How to retrieve recently inserted generated id of the entity?
  • Type of conditional expression cannot be determined because there is no implicit conversion between
  • Word Component in C#
  • How to make invisible datatable when there is no data?
  • Android Room library error: Cannot find setter for field. (Kotlin)
  • Ignoring certain xml lines when merging
  • Primary key in datagrid is always zero
  • Cannot use Turkish characters with Entity Framework
  • python - terminate child process when script invoked from bash
  • Entity Framework Core 1.0.1 add-migration
  • JPA/EclipseLink Returning No Results
  • Insertion large number of Entities into SQL Server 2012 [duplicate]
  • Force show.bind execution
  • Needing to do .toArray() to get output of mongodb .find() on key name not value
  • Groovy: Unexpected token “:”
  • How to create a file in java without a extension
  • Meteor: Do Something On Email Verification Confirmation
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Is there a amazon webstore API for customers?
  • Can Jackson SerializationFeature be overridden per field or class?
  • How to add a column to a Pandas dataframe made of arrays of the n-preceding values of another column
  • script to move all files from one location to another location
  • How to extract text from Word files using C#?
  • MySQL WHERE-condition in procedure ignored
  • Where to put my custom functions in Wordpress?
  • vba code to select only visible cells in specific column except heading
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • RestKit - RKRequestDelegate does not exist
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • KeystoneJS: Relationships in Admin UI not updating
  • WPF Applying a trigger on binding failure
  • trying to dynamically update Highchart column chart but series undefined
  • embed rChart in Markdown
  • Turn off referential integrity in Derby? is it possible?
  • Running Map reduces the dimensions of the matrices
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app
  • Android Heatmap on canvas or ImageView