这是我试图将其转换为 LINQ-Entities 查询的 T-SQL ......
SELECT [a].[ModLimit], [b].[NumberOfMods]
FROM [dbo].[Site][a]
INNER JOIN
(
SELECT [SiteId], ISNULL(COUNT(*),0) AS [NumberOfMods]
FROM [dbo].[Users][a]
WHERE [a].[IsMod] = 1
GROUP BY [SiteId]
) [b] ON [a].[SiteId] = [b].[SiteId]
WHERE [a].[SiteId] = 1
到目前为止我正在使用什么(不编译......)
from u in db.Set<User>()
join s in db.Set<Site>() on u.SiteId equals s.SiteId
let x = t.ModLimit
where s.SiteId == 1
group u by u.SiteId into g
select new { g,x});
想法?
表的缩减结构:
地点
SiteId int PK
ModLimit整数
用户
UserId int PK
SiteId int FK IsMod 位