The system has a Orders 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 Pedido
and ItensDePedido
.
My question is: does the Entity Framework know how to differentiate a Item Novo
from a item Editado
?
I explain better, see the user accesses the Order screen (makes new order) and adds items to the order and then clicks Save and the system adds all the items to the Order, in this situation no doubt:
_repositorio.Pedidos.Add(_pedido);
_repositorio.SaveChanges();
The problem is when the request is changed because the user can add new items to that request and as he had spoken the object _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 the Entity Framework handle this? or do I have to handle this in the code?