c# - 首先在 EF6 代码中创建多对多关系
问题描述
我试图首先使用代码在两个表之间创建多对多关系。
我有如下所示的东西。
public class Railroad
{
public int Id { get; set; }
// Other members...
public ICollection<StorageLocation> StorageLocations { get; set; }
}
public class StorageLocation
{
public int Id { get; set; }
public Provider Provider { get; set; }
// Other members
public ICollection<Railroad> Railroads { get; set; }
}
我读了一篇文章,描述这是正确的方法。但是当我尝试构建迁移时,我得到一个错误。
无法确定“ICollection”类型的导航属性“Railroad.StorageLocations”表示的关系。手动配置关系,或使用“[NotMapped]”属性或使用“OnModelCreating”中的“EntityTypeBuilder.Ignore”忽略此属性。
解决方案
你确定你不上EF Core
?这在 EF Core 之前已支持但现在不支持:
看到这个
在实体框架的早期版本中,此模型定义足以让 EF 暗示正确的关系类型并为其生成连接表。在 EF Core 中,必须在模型中包含一个实体来表示连接表,然后将导航属性添加到指向连接实体的多对多关系的任一侧:
推荐阅读
- android - 从 Single 获取列表
- 可观察的
- angular - 将 ngx-pagination 实现为自定义组件
- android - Android 动画中的 fromXScale 和 fromYScale 是什么意思?
- android - 如何使用 volley 在 Expandable ListView 中映射 childView
- regex - 从字符串python中提取电话号码和传真号码
- python - 值的使用 >> i << i != 值:
- android - 强制 Firebase 动态链接在应用浏览器中打开
- c# - 字符串未被识别为有效的日期时间异常
- cas - 如何使用 LDAP 配置 CAS 5.3
- swisscomdev - Swisscom Application Cloud(公共)的邮件服务替代方案