简体   繁体   English

L2E多对多查询

[英]L2E many to many query

I have four tables: 我有四个表:

Users                  PrivilegeGroups        rdPrivileges        LinkPrivilege
-----------            ----------------       ---------------     ---------------
userId(pk)             privilegeGroupId(pk)   privilegeId(pk)     privilegeId(pk, fk)
privilegeGroupId(fk)   name                   code                privilegeGroupId(pk, fk)

L2E will not create LinkPrivilege entity for me. L2E不会为我创建LinkPrivilege实体。 So we only have Users , PrivilegeGroups and rdPrivileges entities. 因此,我们只有UsersPrivilegeGroupsrdPrivileges实体。 PrivilegeGroups and rdPrivileges are many to many relationship. PrivilegeGroupsrdPrivileges PrivilegeGroups rdPrivileges存在许多关系。

What I need to do is retrieve all code from rdPrivileges table based on a passed in userId. 我需要做的是基于传入的userId从rdPrivileges表中检索所有code How can I do it? 我该怎么做?

EDIT

credite to juharr, the working code: 归功于juharr,其工作代码为:

var codes = from u in db.Users
          from pg in db.PrivilegeGroups
          from p in pg.rdPrivileges
          where u.UserId == passedInUserId
             && u.PrivilegeGroups.PrivilegeGroupId == pg.PrivilegeGroupId
          select p.Code;

I think something like this would work. 我认为类似的方法会起作用。

var codes = from u in Users
            from pg in u.PrivilegeGroups
            from p in pg.rdPrivileges
            where u.userId == "SomeUserID"
            select p.code;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM