似乎Entity Framework Core不尊重我指定为属性属性的外键的自定义名称。我有点担心,因为我认为它最初可以工作。.
Collectionmodel
和ItemModel
之间的一对多关系(过度简化的示例):
[Table("Collections")]
public class Collectionmodel
{
[Key]
public int Id { get; set; }
public string name {get; set; }
public List<ItemModel> Items { get; set; }
}
[Table("Items")]
public class ItemModel
{
[Key]
public int Id { get; set; }
[ForeignKey("FK_Item_CollectionId")] // No sure if it actually respects the convention..
public int CollectionId { get; set; }
}
基本上,它与此exampel相对应(尽管是实体框架6)。我已经遇到过一些Fluent API使用的一些stackoverflow线程,但是希望避免使用它们(即,我遇到其他一些问题。)当我迁移域时(与Entity Framework处于一个单独的项目中)以下名称FK_Items_Collections_ItemModelId
有点长。
我想念什么吗?
感谢您的见解。