在执行分组后,我试图选择所有这些键。如果我将组放入一个变量中然后对变量执行选择,但不是直接在组之后执行选择,它会起作用。我不知道为什么。这不起作用:var pureUsers = from u in userContext.Users join ur in userContext.UserRoles on u.UserID equals ur.UserID join r in userContext.Roles on ur.RoleID equals r.RoleID join sm in userContext.SystemMasters on r.SystemMasterID equals sm.SystemMasterID where sm.SystemName == "PURE" group ur.UserRoleID by u.SAPID into g select g.Key;它给了我错误,“'string'不包含'Key'的定义,并且找不到接受'string'类型的第一个参数的扩展方法'Key'”但是,它是这样工作的:var pureUsers = from u in userContext.Users join ur in userContext.UserRoles on u.UserID equals ur.UserID join r in userContext.Roles on ur.RoleID equals r.RoleID join sm in userContext.SystemMasters on r.SystemMasterID equals sm.SystemMasterID where sm.SystemName == "PURE" group ur.UserRoleID by u.SAPIDvar happy = pureUsers.Select(x => x.Key);我也试过:var pureUsers = (from u in userContext.Users join ur in userContext.UserRoles on u.UserID equals ur.UserID join r in userContext.Roles on ur.RoleID equals r.RoleID join sm in userContext.SystemMasters on r.SystemMasterID equals sm.SystemMasterID where sm.SystemName == "PURE" group ur.UserRoleID by u.SAPID).Select(x => x.Key);它给了我同样的错误。我看不出这与将它放入 pureUsers 然后进行选择有何不同。另外,如果有更好的方法来做到这一点而不涉及分组,请告诉我。我按 SAPID 对其进行分组,因为用户可以拥有多个 UserRoles,并且我想要一个 Users.SPID 列表,其中每个 SAPID 都显示一次。
1 回答
繁花不似锦
TA贡献1851条经验 获得超4个赞
怎么样:
var pureUsers = (from u in userContext.Users
join ur in userContext.UserRoles on u.UserID equals ur.UserID
join r in userContext.Roles on ur.RoleID equals r.RoleID
join sm in userContext.SystemMasters on r.SystemMasterID equals sm.SystemMasterID
where sm.SystemName == "PURE"
select u.SAPID).Distinct();
- 1 回答
- 0 关注
- 183 浏览
添加回答
举报
0/150
提交
取消