问题
In our layered application, we are accessing database via WCF calls. We are creating and disposing contexts per request. Also we are using POCO approach.
My question is, in pure POCO model (completely persistent ignorant POCOs) is it possible to track the changes, while we are creating and disposing context per request (as previous context is disposed in that service call)? If yes how EF handles this situation? As far as I can see 2 mechanisms (snapshot based change tracking and notification based change tracking with proxies) will not be able to handle this? If not, how should we handle context so that we are able to track the changes?
回答1:
Unfortunately you won't find a simple solution to this in Entity Framework v1.0. There has been much discussion and little resolution. It is one of the many known problems with EF v1.0 and one way or another you will end up having to write lot's of code to handle this.
In .NET 4.0 the ADO.NET team have introduced Self-Tracking Entities to tackle this very problem.
回答2:
I'd say:
Do not use self-tracking entities in a pure SOA environment: The self-tracking entities only work when your clients use the generated proxy classes.
When you're doing SOA by the book, you cannot expect your clients to be .Net, or even more, .Net 4.0; Which is the only scenario in which self-tracking entities will work. Your services will be useless to any other clients.
Just My 2 cents, Regards, Koen
回答3:
Self-Tracking Entities does indeed solve this problem if you are capable of sharing the Model with the client as opposed to using metadata generated by the reference.
Abstract the STEs and reference them from the client, you will have access to tracking disconnected from the context.
来源:https://stackoverflow.com/questions/2314995/entitity-framework-change-tracking-in-soa-with-poco-approach