【发布时间】:2021-06-27 16:58:38
【问题描述】:
我正在尝试实现这个所需的架构:
富
FooId
1
2
3
FooMapping
ParentFooId | ChildFooId
1 2
1 3
我想我需要这样的模型:
class Foo
{
public int Id { get; set; }
public Foo Parent { get; set; }
public List<Foo> Children { get; set; }
}
还有这样的配置:
builder.Entity<Foo>().HasMany(c => c.Children).WithOne(c => c.Parent);
现在 EF Core 将采用上述方法并创建如下架构:
富
FooId | ParentId
我觉得从架构/查询的角度来看,一对多的映射表会更有意义,不是吗? EF Core 5 是如何实现的?
【问题讨论】:
-
这只是一个 1:n 的关联,不需要联结表。模式和查询都没有意义。
标签: c# entity-framework entity-framework-core ef-core-5.0