c# - Entity Framework Working with temporary objects -
i'm using ef 4.1 , want perform checks using temporary objects.
the problem i've encountered is, objects written database save changes. tried detach objects, whole object graph gets shredded , can't access referenced objects required checks.
my code looks this:
createtemporder() { order order = new order(); order.customer = dbcontext.customers.single(c => c.id == cid); dbcontext.detach(order); return order; }
are there best practices handle temporary objects in ef or need override detachment procedure?
thanks in advance
if don't want ef track entities can use asnotracking() method:
order = dbcontext.orders.asnotracking().single(o => o.id == oid);
of course works if order entity managed ef.
Comments
Post a Comment