将SQL转换为LINQ查询

时间:2012-01-24 14:29:38

标签: c# sql linq

我有以下SQL查询,我需要在LINQ中使用它,我尝试了几件事,但我无法让它工作。

这是SQL查询

SELECT     ST.Description, ST.STId, COUNT(SI.SIId) AS Expr1
FROM         BP INNER JOIN
                      MbrBP ON BP.BPId = MbrBP.BPId INNER JOIN
                      SI ON BP.BPId = SI.BPId RIGHT OUTER JOIN
                      ST ON SI.STId = ST.STId
WHERE     (BP.CountryId = 1) AND (BP.RegionId = 1) AND (MbrBP.MemberId = 1)
      AND (SI.IsActive = 1)
GROUP BY ST.Description, ST.STId
UNION 
SELECT      ST.Description, ST.STId, COUNT(SI.STId) AS Expr1
FROM         SI RIGHT OUTER JOIN
                      ST ON SI.STId = ST.STId
GROUP BY ST.Description, ST.STId

1 个答案:

答案 0 :(得分:20)

您是否尝试过Linqer http://www.sqltolinq.com

SQL-> LINQ转换器..

或LINQPad http://www.linqpad.net/