R
R
red_gorilla2017-05-24 20:42:19
Java
red_gorilla, 2017-05-24 20:42:19

DDD, Aggregate root without ORM, how to save?

public class Order
{
   List<OrderItem> Items {get; private set;}

   public AddItem(OrderItem item)
   {
       //логика  добавления

       items.Add(item);
   }
}

Following the DDD methodology, all domain logic is located inside the domain and is not taken out into separate services. The question is how to save changes to the aggregation root without using ORM, or using microOrm - Dapper. How are you doing? how the OrderRepository.Save() or Update() method will be implemented if the repository pattern is used, or how the AddItemToOrderCommand command will be implemented if the CQRS pattern is used.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stanislav Silin, 2017-05-25
@byme

And what prevents you from making a typical repository, some of the methods of which will be overridden or new ones will be added relative to the base one for working directly with SQL?

I
Ivan Filatov, 2017-05-25
@NYMEZIDE

Then you will have to (instead of Get and Save) implement a repository with methods

T Find(Guid id);
void Add(T item);
void Update(T item);
void Delete(T item);

D
ddd329, 2018-01-12
@ddd329

Without ORM, there are simple templates. Your repository has a Save method, it doesn’t matter if you updated or created a new UNIT, you pass all this to the Save method, i.e. one method instead of two - Add and Delete. Suppose you are updating an AGGREGATE, which consists of three entities, and there are three tables in the database, i.e. each entity is mapped to its own table. The entity that represents the AGGREGATE root will use the UPDATE statement in the SQL query, and the child entities must be deleted (DELETE FROM ..) and re-inserted (INSERT INTO). All this is done in one database transaction, you don't need any Unit Of Work...
Try it...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question