使用子查询将sql查询转换为linq

时间:2016-07-31 13:39:35

标签: c# sql linq

我有一个包含3个子查询的SQL查询。我需要将查询转换为linq。我尝试了一些方法并得到了错误的答案。你能帮忙吗?

我的SQL查询看起来像这样

match: ->\341<- 

我已经写下了这样的linq查询,但我认为它不是一个好的方法。有没有人能帮助我以一个好的方法做到这一点?我得到了预期的结果。

SELECT  
    COUNT(E.empregid)
FROM 
    Employee E
WHERE 
    E.CardNo IS NOT NULL
    AND E.CorporateId = '10'
    AND E.ReceivedDate < '07/01/2016'
    AND E.empregid NOT IN (SELECT empregid
                           FROM employee
                           WHERE Isinactivated = 1
                             AND DeletionDate < '07/01/2016')
                             AND E.EmpRegId NOT IN (SELECT S.empregid
                                                    FROM Filequeue q, EmpSalary S
                                                    WHERE q.uploadid = S.uploadid
                                                      AND S.CorporateId = '10'
                                                      AND S.RecordStatus = 'E'
                                                      AND S.ModifiedDate between '06/01/2016' AND '06/30/2016'
                                                      AND q.uploadid NOT IN 
                                                          (SELECT uploadid 
                                                           FROM Filequeue 
                                                           WHERE remarks LIKE 'New%' 
                                                             AND mode = 'C'))

0 个答案:

没有答案