小编use*_*153的帖子

SQL到LINQ有多个join,count和left join

我用多个JOIN(包括一个LEFT JOIN)写了这个SQL请求.
它给了我预期的结果.

SELECT DISTINCT c.Id, 
       c.Title, 
       COUNT(v.Id) AS 'Nb_V2',
       COUNT(DISTINCT v.IdUser) AS 'Nb_V1',
       r.cnt AS 'Nb_R'
FROM TABLE_C c
JOIN TABLE_V v on c.Id = v.Id
LEFT JOIN ( 
    SELECT Id, COUNT(*)  AS cnt 
    FROM TABLE_R 
    GROUP BY Id
) r ON c.Id = r.Id
WHERE c.IdUser = '1234'
GROUP BY c.Id, c.Title, r.cnt
Run Code Online (Sandbox Code Playgroud)

但是,'Id喜欢Linq等同于此请求,将它放在我的应用程序的数据访问层.

我尝试过类似的东西:

var qResult = from c in dbContext.TABLE_C
              join v in dbContext.TABLE_V on c.IdC equals v.IdC
              join r in …
Run Code Online (Sandbox Code Playgroud)

sql linq join left-join sql-to-linq-conversion

3
推荐指数
1
解决办法
1215
查看次数

标签 统计

join ×1

left-join ×1

linq ×1

sql ×1

sql-to-linq-conversion ×1