我有以下型号。我正在尝试使用ASP.NET MVC 5的Code First New Database方法。
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; }
}
Ibo.cs
public class Ibo
{
[Key]
public int IboID { set; get; }
[Required]
[Display(Name="Full Name")]
public string Name { set; get; }
[Required]
[RegularExpression(@"^\d+$", ErrorMessage = "The IBO number you've input must contain only numbers.")]
[Display(Name = "IBO Number")]
public string IboNumber { set; get; }
[Required]
[StringLength(100, ErrorMessage = "The Phone number must be at least {2} numbers long.", MinimumLength = 7)]
public string Phone { set; get; }
[Required]
public string Address { set; get; }
[Required]
[NotMapped]
public string Username { set; get; }
[Required]
[UIHint("EmailAddressAttribute")]
[NotMapped]
public string Email { set; get; }
[Required]
[DataType(DataType.Password)]
public string Password { set; get; }
[Display(Name="Confirm Password")]
[DataType(DataType.Password)]
[Compare("Password")]
[NotMapped]
public string PasswordConfirm { set; get; }
[NotMapped]
public string SelectedSecurityQ { set; get; }
[Display(Name="Security Question")]
public int SecurityQuestionID { set; get; }
[Required]
[Display(Name="Your answer")]
public string SecurityAnswer { set; get; }
public virtual SecurityQuestions SecurityQuestions { set; get; }
}
Mods.cs
public class Mods
{
public int ModsID { set; get; }
public int IboID { set; get; }
public virtual ICollection<Ibo> Ibo { set; get; }
}
Order.cs
public class Order
{
public int OrderID { set; get; }
public int IboID { set; get; }
public int ClientID { set; get; }
public DateTime Created { set; get; }
public DateTime Modified { set; get; }
public virtual ICollection<Ibo> Ibo { set; get; }
public virtual ICollection<Client> Client { set; get; }
}
OrderProcess.cs
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; }
}
Product.cs
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;
}
SecurityQuestions.cs
public class SecurityQuestions
{
public int ID { set; get; }
public string SecurityQuestion { set; get; }
public virtual ICollection<Ibo> Ibo { get; set; }
}
我要做的是设置以下关系。我很困惑何时以及如何使用ICollection&lt;&gt ;, List&lt;&gt;或与虚拟键盘类似。
我还试图在AspNetUsers表中创建新用户时在Ibo表中生成新的IboID条目。
这样的事情:
public virtual ICollection<Ibo> Iboes
任何参考,建议将不胜感激!提前致谢