我有一個名爲ProductTypeId
的外鍵屬性的產品模型。但是,我沒有ProductType
模型。相反,我有一個TypeListItem
模型。我想告訴EF仍然創建從ProductTypeId
到Id
,TypeListItem
表中的關係。使用Entity Framework Core Fluent API映射外鍵帶有不同名稱
我想使用實體框架核心流利的API來指定這一點,但無法弄清楚如何。我相信我曾經使用過HasRequired
,但我不認爲EF Core可用。
這裏是有問題的型號:
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public int ProductTypeId { get; set; }
}
public class TypeListItem
{
public int Id { get; set; }
public string Name { get; set; }
}
我認爲我可能需要的TypeListItem
導航屬性添加到Product
模型,使這個可能嗎?
你能在問題發佈樣本模型類? –
@IvanStoev我更新了我的帖子以顯示此內容。 –