实体框架 - 相关的 ICollection 被具体化为 HashSet
我在我的项目中使用 EntityFramework POCO + 代理 + 延迟加载。今天,我非常惊讶地发现类 Transaction
的相关集合 Rows
已具体化为 HashSet
(而不是 EntityCollection
) >)。我需要 EntityCollection 来跟踪集合中的更改。
public class Transaction
{
public virtual ICollection<TransactionRow> Rows { get; set; }
}
然而,其他实体类将其相关集合具体化为EntityCollection
。
我正在通过 ObjectQuery
加载 Transaction
,因此它应该位于上下文中。该对象的代理也被创建。
谁能告诉 - 实体框架如何决定使用什么 - HashSet 还是 EntityCollection?为什么有些东西会变成HashSet?
I use EntityFramework POCO + proxies + lazy loading in my project. Today I was pretty surprized to see that the class Transaction
has its related collection Rows
materialized into HashSet
(instead of EntityCollection
). I need EntityCollection
for tracking changes in the collection.
public class Transaction
{
public virtual ICollection<TransactionRow> Rows { get; set; }
}
However other entity classes have their related collection materialized into EntityCollection
.
I am loading the Transaction
through ObjectQuery
, so it should be in the context. The proxy for the object is also created.
Could anyone tell - how does Entity Framework decide what to use - HashSet or EntityCollection? Why some thing become HashSets?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅当满足以下两个条件时才会创建更改跟踪代理:
Change tracking proxy is created only when these two conditions are met: