【发布时间】:2020-05-06 16:56:44
【问题描述】:
我正在尝试使用 Fluent API 在实体框架核心中创建多对多关系 这是我的第一个模型:
MyCalculationSelector.cs
public int SortOrder { get; set; }
public string UserString { get { return Name; } }
private IList<CalculationType> _calculationTypes;
public virtual IList<CalculationType> CalculationTypes
{
get { return _calculationTypes; }
set { _calculationTypes = value; }
}
这是我的第二个模型:
MyCalculationType.cs
public int SortOrder { get; set; }
public string UserString
{
get { return Name; }
}
public int CalculationMethod { get; set; }
我记得 EF 6 可以轻松地从 Fluent API 建立多对多关系:
modelBuilder.Entity<MyCalculationSelector>().HasMany(x => x.MyCalculationTypes).WithMany();
我们可以在 ef core 中实现这样的事情吗?截至今天,Hasmany-Withmany 实现是不可能的
【问题讨论】:
-
EF Core 文档 -> 关系 -> Many-to-many
-
感谢@IvanStoev 只是关注文档,但是没有导航属性的多对多关系并不多
-
我建议阅读整个Relationships 部分。比如Single navigation property或Without navigation property等有共同话题。
-
我已经阅读了几次文档,但是与 ef6 相比,ef core 仍然缺乏一些东西,我正在认真考虑迁移到另一种技术
标签: c# entity-framework ef-code-first ef-fluent-api ef-core-3.0