类 的结构具有从 entity framework 生成的外键关系

structure of the classes having foreign key relationship generated from entity framework

我通过 Entity Framework 从数据库生成了我的 classes。 classes 名称是 tables 名称,属性是字段。 现在我有三本 table、App_users、书籍、课程。

App_users与book和course一对多关系(userid为外键)。当我看到用户 class 时,它的结构如下:

public partial class App_users
{
    public App_users()
    {
        this.Book = new HashSet<Book>();
        this.Course = new HashSet<Course>();
    }

    public int USERID { get; set; }
    public string USERNAME { get; set; }
    public virtual ICollection<Book> Book { get; set; }
    public virtual ICollection<Course> Course { get; set; }
}
  1. 我想知道为什么这些 tables (Book & Course) 在构造函数中被定义为 HASHSET。这样做的use/importance是什么?
  2. 再次 classes 书籍和课程定义为 ICOLLECTION。这样做的 use/importance 是什么?

我知道这个结构是用来显示table中的外键关系的。

谁能给我解释一下。

第一个问题:

The HashSet is mostly useful in situations where insertion and removal times are very important, such as when processing data. It is also extremely useful for comparing sets of data (again when processing) using operations like intersect, except, and union. In any other situation, the cons generally outweigh the pros. ()

第二个问题:

ICollection<> (MSDN: http://msdn.microsoft.com/en-us/library/92t2ye13.aspx) for a list of objects that needs to be iterated through and modified, List<> for a list of objects that needs to be iterated through, modified, sorted, etc (See here for a full list: http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx).