【问题标题】:Working with Sets of Self-Tracking Entities causing performance issues使用导致性能问题的自跟踪实体集
【发布时间】:2011-04-12 15:18:38
【问题描述】:
我看到了 ADO.Net 团队的 Post,它看起来很有前途,直到我开始在我的应用程序中使用它。我有近 100 个自我跟踪实体的 EF 4.0 模型。在我的项目中包含迭代器后,任何扩展方法“StartTrackingAll”或“StopTrackingAll”都需要 5 秒才能完成。有没有人遇到过同样的问题或任何人知道任何更好的选择。
【问题讨论】:
标签:
entity-framework-4
iterator
ado.net-entity-data-model
self-tracking-entities
【解决方案1】:
你的实体有关系吗?在这种情况下,您不需要使用StartTrackingAll,因为StartTracking 本身starts tracking for whole object graph:
StartTracking 方法指示
更改实体上的跟踪器以启动
记录应用到
实体。这包括对
标量属性、集合和
对其他实体的引用。这
自追踪实体开始追踪
自动当他们
通过反序列化到客户端
Windows 通信基金会
(WCF)。跟踪也打开了
对于新创建的实体
以下场景:
* A relationship is created between the new entity and an entity that is already tracking changes.
* The MarkAs[State] or AcceptChanges method is called on an entity.
如果您不使用相关实体,您需要同时跟踪 100 个实体听起来很奇怪。此外,如果实体没有关系,则可能根本不需要跟踪它们。