如何将包含INNER LOOP JOIN的SQL查询转换为LINQ?

时间:2015-01-06 11:30:14

标签: sql sql-server linq

我无法将以下查询转换为LINQ。子句INNER LOOP JOIN无法将查询转换为LINQ。

SQL查询:

SELECT
    b.tm_runManagerID,
    b.testName,
    b.startDate,
    b.endDate,
    SUM( CASE WHEN c.testPass = 1 THEN 1 ELSE 0 END) AS passNumber,
    SUM( CASE WHEN c.testPass = 0 THEN 1 ELSE 0 END) AS failNumber,
    SUM(1) AS totalNumber,
    b.status
FROM dbo.tm_actionManager a WITH (NOLOCK)
    INNER LOOP JOIN [tm_runManager] b WITH (NOLOCK) ON a.tm_runManagerID = b.tm_runManagerID
    LEFT OUTER JOIN dbo.tm_testResult c WITH (NOLOCK) 
    on a.tm_actionManagerID = c.tm_actionManagerID AND c.nodeCompared = 'overallresult'
    WHERE   a.tm_runManagerID IN (SELECT tm_runManagerID FROM dbo.tm_runManager (NOLOCK) WHERE isActive = 1)
    GROUP BY b.tm_runManagerID,b.testName,b.startDate,b.endDate,b.status
    ORDER BY b.tm_runManagerID DESC 

1 个答案:

答案 0 :(得分:2)

LOOPHASHMERGE加入提示。它指定查询中的JOIN应使用循环,散列或合并。它只是一个提示,以便数据库可以优化查询,并且通常不会使用,除非在极少数情况下自动优化是不够的。

因此,LINQ没有翻译。大多数情况下,由于您的SQL代码无论如何都会有所不同,您可以放心地忽略它。