我正在尝试构建一个非常广泛的数据库重型Web应用程序,并且很少有经验。我想弄清楚的是通过脚手架在实体框架中创建一个关系表。
看来我已经意外地用这两个模型完成了这个,但我不知道它是怎么发生的:
namespace FlavorPing.Models
{
public class MenuItem
{
[Key]
public int MenuItemID { get; set; }
public string ItemName { get; set; }
public string Description { get; set; }
//Category
//May need to put this back and add to controllers and views.
//[ForeignKey("Merchant")]
//public int MerchantID { get; set; }
public virtual Merchant Merchant { get; set; }
public ICollection<Follower> Followers { get; set; }
}
}
public class Merchant
{
//Meant to inherit identity.
[ForeignKey("ApplicationUserId")]
public string ApplicationUserId { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
[Key]
public int MerchantID { get; set; }
[Required]
[Display(Name = "Business Name")]
public string MerchantName { get; set; }
[Required]
[Display(Name = "Email")]
[DataType(DataType.EmailAddress)]
public string email { get; set; }
//need to create formatting here.
[Required]
[Display(Name = "Web Site Link")]
public string website { get; set; }
public int MenuItemID { get; set; }
public virtual List<MenuItem> MenuItems { get; set; }
public virtual MerchantDetails MerchantDetails { get; set; }
}
上面的模型有自己的专用表,但第二个表 MenuItemFollowers 是用MenuItemID
和FollowerID作为columuns创建的,我想要,但我不知道我是怎么做的这个并且需要知道所以我可以在这个表中添加另一个ID。