Answer the question
In order to leave comments, you need to log in
DDD, Aggregate root without ORM, how to save?
public class Order
{
List<OrderItem> Items {get; private set;}
public AddItem(OrderItem item)
{
//логика добавления
items.Add(item);
}
}
Answer the question
In order to leave comments, you need to log in
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?
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);
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 questionAsk a Question
731 491 924 answers to any question