![](/img/trans.png)
[英]How to define a second Entity Framework Core relationship to the same foreign key?
[英]How to define foreign Key in Entity Framework Core
我正在嘗試實現下表結構,但出現錯誤“不能用作實體類型的屬性,因為它被配置為導航。”
誰能幫我。
類別:<\/strong>
ID<\/th> | 名稱<\/th><\/tr><\/thead> | |||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1<\/td> | 貓1<\/td><\/tr> | |||||||||||||||||||||||||||||||||||||||||
2<\/td> | 貓2<\/td><\/tr> | |||||||||||||||||||||||||||||||||||||||||
3<\/td> | 三類<\/td><\/tr> | |||||||||||||||||||||||||||||||||||||||||
4<\/td> | 第四類<\/td><\/tr><\/tbody><\/table> 子類別:<\/strong>
|
在項目類中只保留子類別,因為它已經依賴於類別並且具有一對一的關系
public class Item
{
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
public int? SubCategoryId { get; set; }
public virtual SubCategory SubCategory { get; set; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.