自我跟踪实体的目的是什么?

发布于 2024-10-18 20:29:53 字数 177 浏览 1 评论 0原文

我一直在阅读有关 .net 中的自我跟踪实体以及如何从 *.edmx 文件生成它们的内容。我很难理解的是,生成这些实体会给您带来什么超过基本 EF 实体的结果?另外,有些人提到了自我跟踪实体和 Silverlight,但为什么要使用这些而不是客户端或 RIA 服务生成的共享类?

自我跟踪实体的意义是什么?为什么要使用它们?

I've been reading about self-tracking entities in .net and how they can be generated from a *.edmx file. The thing that I'm struggling to understand is what generating these entities gives you over the basic EF entities? Also, some people have mentioned self tracking entities and Silverlight, but why would you use these rather than the client side or shared classes generated by RIA services?

What is the point of self-tracking entities and why would you use them?

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

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

发布评论

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

评论(2

倚栏听风 2024-10-25 20:29:53

自跟踪实体 (STE) 是变更集的实现(以前的变更集的 .NET 实现是 DataSet)。 STE 与其他实体类型(POCO、EntityObject)之间的区别在于,常见实体类型仅在连接到活动 ObjectContext 时才能跟踪更改。一旦通用实体被分离,它就失去了任何变更跟踪能力。这正是 STE 所解决的问题。即使您将 STE 与 ObjectContext 分离,STE 也能够跟踪更改。

STE 的常见用法是在断开连接的场景中,例如通过 Web 服务进行 .NET 到 .NET 通信。对 Web 服务的第一个请求将创建并返回 STE(实体在序列化时分离,并且 ObjectContext 仅用于服务单个调用)。客户端将在 STE 中进行更改并在另一个 Web 服务调用中将其传回。服务将能够处理变更,因为它将提供 STE 内部变更跟踪。

在没有更改跟踪的情况下处理这种情况是可能的,但它要复杂得多,特别是当您使用整个对象图而不是单个实体时 - 您必须 手动将从客户端收到的更改合并到数据库中的当前状态。

请注意,STE 不适用于可互操作的解决方案,因为它们的功能基于在服务器和客户端之间共享 STE 代码。

Self tracking entities (STE) are implementation of change set (previous .NET implementation of change set is DataSet). The difference between STE and other entity types (POCO, EntityObject) is that common entity types can track changes only when connected to living ObjectContext. Once common entity is detached it loose any change tracking ability. This is exactly what STE solves. STE is able to track changes even if you detach it from ObjectContext.

The common usage of STE is in disconnected scenarios like .NET to .NET communication over web services. First request to web service will create and return STE (entity is detached when serialized and ObjectContext lives only to serve single call). Client will make changes in STE and pass it back in another web service call. Service will be able to process changes because it will have STE internal change tracking available.

Handling this scenario without change tracking is possible but it is much more complex especially when you work with whole object graph instead of single entity - you must manually merge changes received from client to current state in database.

Be aware that STEs are not for interoperable solutions because their functionality is based on sharing STE code between server and client.

oО清风挽发oО 2024-10-25 20:29:53

主要目的是帮助N层开发。由于它们是自我跟踪的,因此您可以通过 WCF 服务等对它们进行序列化,然后将它们反序列化回来,它们仍然会知道已进行哪些更改以及哪些更改正在数据库中等待处理。

自我跟踪实体知道该怎么做
不管怎样他们自己的变更跟踪
这些更改是在哪一层进行的
在。作为一种架构,自我追踪
实体介于 DTO 和
数据集并包括一些
各有好处。

http ://blogs.msdn.com/b/efdesign/archive/2009/03/24/self-tracking-entities-in-the-entity-framework.aspx

The main purpose is to aid in N-tier development. Since they're self-tracking, you can serialize them over, say, a WCF service, then de-serialize them back, and they will still know which changes have been made, and are pending for the database.

Self-tracking entities know how to do
their own change tracking regardless
of which tier those changes are made
on. As an architecture, self-tracking
entities falls between DTOs and
DataSets and includes some of the
benefits of each.

http://blogs.msdn.com/b/efdesign/archive/2009/03/24/self-tracking-entities-in-the-entity-framework.aspx

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