[英]Fluent API, define a primary key as foreign key
我有這兩個模型:
//Primary AND Foreign key 1
public int UserID {get; set;}
//Primary AND Foreign key 2
public int ProductID {get; set;}
我不知道如何將這兩列同時設置為主鍵和外鍵! 你能幫助我嗎 ?
可能您正在尋找這個
//Primary AND Foreign key 1
[Key]
public int UserID {get; set;}
[ForeignKey("UserID")]
public virtual IEnumerable<UserProfile> users;
//Primary AND Foreign key 2
public int ProductID {get; set;}
[ForeignKey("ProductID")]
public virtual IEnumerable<Product> products;
這將允許您從用戶瀏覽到產品。
如果這不是您想要的內容,請提供更多有關所需內容的詳細信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.