自我跟踪实体的目的是什么?
我一直在阅读有关 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自跟踪实体 (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 livingObjectContext
. 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 fromObjectContext
.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.
主要目的是帮助N层开发。由于它们是自我跟踪的,因此您可以通过 WCF 服务等对它们进行序列化,然后将它们反序列化回来,它们仍然会知道已进行哪些更改以及哪些更改正在数据库中等待处理。
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.
http://blogs.msdn.com/b/efdesign/archive/2009/03/24/self-tracking-entities-in-the-entity-framework.aspx