linking the EF 4.0 context to the WCF call context
I would like to create an Entity Framework 4.0 context when a call is received and invoke to save changes when it finish, (som开发者_如何学JAVAething 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?
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:
- Building N-Tier apps with EF4
- More on disconnected Entity Framework
- Attaching modified entities in EF4
精彩评论