views:

130

answers:

1

Hello,

I would like to create an Entity Framework 4.0 context when a call is received and invoke to save changes when it finish, (something like JPA).

I think it is a good idea because I can use the state for all the call, It is short and encapsulate enogh to be threadsafe and long enough for caching calls and the context itself.

Any idea how is the best way for implement this?

+1  A: 

Yes, definitely, that's the best way to go.

By default and by best practice recommendation, WCF service calls are "per-call", e.g. each requests gets a brand new, dedicated instance of the service class all to itself - no messy multithreaded/concurrency stuff to deal with - just a nice clean execution environment.

With EF 4, the "disconnected" scenario of sending back entities through WCF was one of the (many) areas that the EF team focused on. See some of these resources for more information:

marc_s
but i would like to connect the EF context to the per-call wcf context. Do you know an elegant way to do it?
Pablo Castilla
@pablocastilla: I don't really know what you're trying to do..... you can instantiate the EF EntityContext in the constructor of your service class and then use it in whichever method might have been called....
marc_s