Entity Framework - related ICollection getting materialized into HashSet

柔情痞子 提交于 2019-12-21 04:52:29

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/3624701/entity-framework-related-icollection-getting-materialized-into-hashset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!