Base solution for your next web application
Open Closed

DDD Aggregate Root #2534


User avatar
0
bilalhaidar created

Hi,

In the case of using Aggregate Roots. I noticed that in the template, with any change in an entity, the data is being saved to the database (UOW).

In the case of Aggregate Roots, once you are adding objects, updating, etc. then you would save changes to the database. (DDD)

How to have the same behavior in a sense not to save to the database at every field change but rather group all changes at once?

To illustrate more, consider Event aggregate root and one of the collections it manages is EventRegistration. So when following DDD guidelines, I would create a new event registration and add it to the collection of event registrations on Event aggregate root. Then, I would save to database by calling Update() or so.

I cannot figure out how to visualize the above when using the boilertemplate. Shall I disable UOW and use it manually? Or is there a better approach?

Thanks


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    UoW works exactly like you want, See <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#DocAutoSaveChanges">http://aspnetboilerplate.com/Pages/Docu ... aveChanges</a> and <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#DocUowSaveChanges">http://aspnetboilerplate.com/Pages/Docu ... aveChanges</a>

    Please write back if you think it does not fit for your case.

  • User Avatar
    0
    bilalhaidar created

    So in other words, every action on an entity (changing 1 or more fields) causes UOW to save changes to DB?

    So if I have 4 methods on an entity, each method to edit 1 property, I will end up hitting DB 4 times as each method would run and cause UOW to save data to the database?

    Thanks, Bilal

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    If you call SaveChanges manually, it will access the DB, otherwise it will commit at the end of your App service method or controller action.