LINQ查询帮助-多对多相关
在我的数据库中,我有一个用户表和一个工作组表,以及多对多关系。一位用户可以属于一个或多个工作组。我正在为我的 ORM 使用实体框架(EF 4.1 Code First)。
用户表有用户:
1,2,3,4,5,6,7,8,9,10
工作组表有工作组:
A,B,C, D
工作组用户表有条目
A1, A2, A3, A4, A5
B1, B3, B5, B7, B9
C2, C4, C6, C8, C10
D1, D2, D3, D9, D10
我想做的是: 给定用户 4,它属于工作组 A、C 并且具有共同的用户
1,2,3,4,5 (from workgroup A) and
2,4,6,8,10 from workgroup C
,并且不同的共同用户集是 1,2,3,4,5,6,8,10
我如何为此编写 LINQ 语句(最好使用流畅的 API)?
谢谢你,
In my database, I have a user table and a workgroup table, and a many-to-many relationship. A user can belong to one or more workgroups. I am using entity framework for my ORM (EF 4.1 Code First).
User Table has users:
1,2,3,4,5,6,7,8,9,10
Workgroup table has workgroups:
A,B,C, D
WorkgroupUser table has entries
A1, A2, A3, A4, A5
B1, B3, B5, B7, B9
C2, C4, C6, C8, C10
D1, D2, D3, D9, D10
What I would like to do is:
Given user 4, it belongs to workgroups A,C
and has common users
1,2,3,4,5 (from workgroup A) and
2,4,6,8,10 from workgroup C
and the distinct set of users in common is 1,2,3,4,5,6,8,10
How do I write a LINQ statement (preferably in fluent API) for this?
Thank you,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是总体思路(因为我不知道 User 和 WorkGroup 实体的属性)
Here's the general idea (since I don't know the properties of User and WorkGroup entity)