实体框架相关ICollection实现到HashSet [英] Entity Framework - related ICollection getting materialized into HashSet

查看:277
本文介绍了实体框架相关ICollection实现到HashSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用EntityFramework POCO +代理+懒惰加载。今天,我非常漂亮,看到课程交易有其相关集合行实现为 HashSet (而不是 EntityCollection )。我需要 EntityCollection 来跟踪集合中的更改。

  public class Transaction 
{
public virtual ICollection< TransactionRow>行{get;组; }
}

然而,其他实体类将其相关集合实现为 EntityCollection



我正在加载交易通过 ObjectQuery ,所以它应该在上下文中。对象的代理也被创建。



有没有人可以告诉 - Entity Framework如何决定使用什么 - HashSet或EntityCollection?为什么有些事情变成HashSets?

解决方案

只有满足这两个条件,才能创建更改跟踪代理:




  • POCO类是公开的,非密封的和非抽象的

  • 所有持久属性与getter和setter)被标记为虚拟


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?

解决方案

Change tracking proxy is created only when these two conditions are met:

  • POCO class is public, non-sealed and non-abstract
  • All persisted properties (with getter and setter) are marked as virtual

这篇关于实体框架相关ICollection实现到HashSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆