C# 如何设置导航属性-代码优先-实体框架?

C# 如何设置导航属性-代码优先-实体框架?,c#,asp.net-mvc,entity-framework,asp.net-mvc-5,C#,Asp.net Mvc,Entity Framework,Asp.net Mvc 5,我有以下几种型号。我试图在ASP.NETMVC5中使用代码优先的新数据库方法 Client.cs public class Client { public int ID { get; set; } public int Name { set; get; } public string Phone { set; get; } public string Email { get; set; } public

我有以下几种型号。我试图在ASP.NETMVC5中使用代码优先的新数据库方法

Client.cs

   public class Client
    {
        public int ID { get; set; }
        public int Name { set; get; }
        public string Phone { set; get; }
        public string Email { get; set; }
        public string Address { set; get; }
        public Ibo IboID { set; get; }
        public DateTime LastOrder { get; set; }

        public virtual ICollection<Ibo> Ibo { set; get; }
    }
Mods.cs

 public class Mods
    {
        public int ModsID { set; get; }
        public int IboID { set; get;  }

        public virtual ICollection<Ibo> Ibo { set; get; }
    }
安全问题

 public class SecurityQuestions
    {
        public int ID { set; get; }
        public string SecurityQuestion { set; get; }
        public virtual ICollection<Ibo> Ibo { get; set; }
    }
公共类安全问题
{
公共int ID{set;get;}
公共字符串安全性问题{set;get;}
公共虚拟ICollection Ibo{get;set;}
}
我想做的是建立以下关系。我对何时以及如何在虚拟键盘上使用ICollection、List或Similar感到非常困惑

我还试图在AspNetUsers表中创建新用户时,在Ibo表中生成一个新的IboID条目

大概是这样的:

public virtual ICollection<Ibo> Iboes 
公共虚拟ICollection Iboes


如有任何推荐、建议,将不胜感激!提前感谢

您正确地公开了您的属性中的ICollection。在类的构造函数中,可以将空列表对象分配给此属性,因为列表实现ICollection。这个问题是针对
HashSet
的,但它涉及到为什么要为ICollection属性选择特定的具体实现。问题是我不知道在模型中把ICollection放在哪里,我应该把哪个类传递给参数,所以它实际上链接了它们。我还不能完全理解这一点。我不知道何时使用virtual关键字和/或将其与ICollection/List组合使用。我不知道我是否需要使用它们!
 public class OrderProcess
    {
        public int OrderProcessID {set; get;}
        public int OrderID { set; get; }
        public DateTime TimeStamp { set; get; }
        public int ProductID { set; get; }
        public int State { set; get; }
        public decimal ProductCost { set; get; }

        public virtual ICollection<Order> Order { set; get; }
        public virtual ICollection<Product> Product { set; get; }

    }
   public class Product
    {
        public int ID;

        public string ProductID;

        public string ProductName;

        public string ProductDesc;
        public decimal Pv;
        public decimal Bv;



        public decimal PriceIbo_2014_09;

        public decimal PriceSug_2014_09;
        //If Product is taxable
        public bool Tax;
        public int State;
        public decimal Price_Ibo_2014_09;
        public decimal Price_Sug_2014_09;
        public int Status;
    }
 public class SecurityQuestions
    {
        public int ID { set; get; }
        public string SecurityQuestion { set; get; }
        public virtual ICollection<Ibo> Ibo { get; set; }
    }
public virtual ICollection<Ibo> Iboes