添加一個外鍵Id屬性我有兩個類我需要在MVC模型的代碼首先
public class Shop
{
public int Id { get; set;}
public string Name { get; set;}
public virtual ICollection<Product> Products { get; set; }
}
public class Product
{
public int Id { get; set;}
public virtual Shop Shop {get;set;}
//Do i need this line as well?
public int ShopId {get;set;}
}
我的問題是,我需要定義ShopId?我看到很多代碼示例,有時它在那裏,有時不是。