EF4 + STE: Reattaching via a WCF Service? Using a new objectcontext each and every time?
Posted
by
Martin
on Stack Overflow
See other posts from Stack Overflow
or by Martin
Published on 2011-01-09T10:16:44Z
Indexed on
2011/01/09
17:53 UTC
Read the original article
Hit count: 219
Hi there,
I am planning to use WCF (not ria) in conjunction with Entity Framework 4 and STE (Self tracking entitites). If i understnad this correctly my WCF should return an entity or collection of entities (using LIST for example and not IQueryable) to the client (in my case silverlight)
The client then can change the entity or update it. At this point i believe it is self tracking???? This is where i sort of get a bit confused as there are a lot of reported problems with STEs not tracking..
Anyway... Then to update i just need to send back the entity to my WCF service on another method to do the update. I should be creating a new OBJECTCONTEXT everytime? In every method?
If i am creaitng a new objectcontext everytime in everymethod on my WCF then don't i need to re-attach the STE to the objectcontext?
So basically this alone wouldn't work??
using(var ctx = new MyContext())
{
ctx.Orders.ApplyChanges(order);
ctx.SaveChanges();
}
Or should i be creating the object context once in the constructor of the WCF service so that 1 call and every additional call using the same wcf instance uses the same objectcontext?
I could create and destroy the wcf service in each method call from the client - hence creating in effect a new objectcontext each time.
I understand that it isn't a good idea to keep the objectcontext alive for very long.
Any insight or information would be gratefully appreciated
thanks
© Stack Overflow or respective owner