【发布时间】:2020-01-26 09:16:57
【问题描述】:
这么多对多没有进入 .NET Core 3.0 版本,真糟糕……
我知道如何使用连接实体实现 m:m,如下例所示:https://stackoverflow.com/a/53972658/980917
我的问题是关于模型类本身。以学生和班级为例:
Student - has ICollection<StudentClass>
StudentClass - joining entity
Class - has ICollection<StudentClass>
这对于数据加载来说很好。但是在您的 StudentClasses 业务逻辑集合中没有用,因为它只是一个具有 2 个 ID 的连接实体。当使用 Student 或 Class 时,您实际上需要 Student 中的 Classes 的实际集合和 Student 的集合班级内的strong>学生。 (即:Student.Classes & Class.Students。
目前推荐的检索多对多集合(不加入实体)的方法/解决方法是什么?
我们是否必须根据加入实体进行第二次选择,还是有更优雅的方法?
一个简单的例子或一个链接会很棒。谢谢。
【问题讨论】:
-
What's the current recommended approach / workaround to populate those list when pulling data?- 最后一部分我不清楚。请你说清楚好吗? -
添加了更多细节。基本上,检索多对多实体的推荐方法是什么(不加入实体,因为它在业务逻辑中没有用处)。
-
请检查我的回答。
标签: entity-framework .net-core entity-framework-core many-to-many ef-core-3.0