Entitity Framework: Change tracking in SOA with POCO approach

我是研究僧i 提交于 2019-12-07 00:26:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!