我有两张桌子:
1:角色
2:UserRoles
请考虑以下命令:
在SQL中:
SELECT RoleID, RoleName,
(SELECT COUNT(UserID) AS UserCount
FROM dbo.UserRoles AS UR
WHERE (RoleID = R.RoleID)) AS UserCount
FROM dbo.Roles AS R
实体框架中的相同脚本是什么?
答案 0 :(得分:2)
这是LINQ to Entities查询,例如:
var q = from role in context.Roles
select new {
role.RoleID,
role.RoleName,
UserCount = role.UserRoles.Count()
};