实体框架:使用 POCO 方法跟踪 SOA 中的变更

发布于 2024-08-23 06:54:27 字数 236 浏览 7 评论 0原文

在我们的分层应用程序中,我们通过 WCF 调用访问数据库。我们正在根据请求创建和处置上下文。我们也使用 POCO 方法。
我的问题是,在纯 POCO 模型(完全持久的无知 POCO)中,当我们为每个请求创建和处置上下文时(因为之前的上下文是在该服务调用中处置的),是否可以跟踪更改?如果是的话EF如何处理这种情况?据我所知,两种机制(基于快照的更改跟踪和基于代理的更改跟踪通知)将无法处理此问题?如果不是,我们应该如何处理上下文以便我们能够跟踪更改?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瀞厅☆埖开 2024-08-30 06:54:27

我想说:

不要在纯 SOA 环境中使用自跟踪实体:
自我跟踪实体仅在您的客户使用时才起作用
生成的代理类。

当您按规矩进行 SOA 时,您不能指望您的客户
成为.Net,甚至更高,.Net 4.0;这是唯一的场景
自我跟踪实体将在其中发挥作用。您的服务将是
对任何其他客户都没用。

只是我的 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

动次打次papapa 2024-08-30 06:54:27

如果您能够与客户端共享模型而不是使用引用生成的元数据,那么自我跟踪实体确实可以解决此问题。

抽象STE并从客户端引用它们,您将可以访问与上下文断开连接的跟踪。

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.

看春风乍起 2024-08-30 06:54:27

不幸的是,您在 Entity Framework v1.0 中找不到简单的解决方案。
有很多讨论 分辨率很低。这是 EF v1.0 的众多已知问题之一,无论如何您最终将不得不编写大量代码来处理这个问题。

在 .NET 4.0 中,ADO.NET 团队引入了 自我跟踪实体来解决这个问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文