2
The system has an Order screen where you can add new items or change items from that order.
The object that is sent to the Repository layer is a complex object 1 x N
, that is to say Pedido
and ItensDePedido
.
My question is this: the Entity Framework knows how to differentiate a Item Novo
of a item Editado
?
I explain better, see the user access the Order screen (make new order) and add items to the order and then click Save and the system adds all items to the Order, in this situation no doubt:
_repositorio.Pedidos.Add(_pedido);
_repositorio.SaveChanges();
The problem is when the order is changed, because the user can add new items to this request and as the object had said _pedido
is a complex object there may be items that already exist in the database and items that do not exist.
_repositorio.Entry(_pedido).State = EntityState.Modified;
_repositorio.SaveChanges();
Should Entity Framework handle this ? or should I handle it in the code ?