简体   繁体   English

将带有 LEFT 连接的 sql 查询转换为 lambda 或 Linq 表达式

[英]Convert sql query with LEFT join into lambda or Linq expression

I have below SQL query and I want it to convert into either Lambda or Linq expression for C# .我有以下SQL查询,我希望它转换为C# LambdaLinq表达式。

SELECT DISTINCT employeeid
INTO #temp
FROM [dbo].DOCS
WHERE companyid = 1
    AND taxyear = 2015

SELECT DISTINCT e.EmployeeId,
                e.EmployeeName
FROM Employees e
LEFT JOIN #temp t ON e.EmployeeId = t.employeeid
WHERE CompanyId = 1
ORDER BY EmployeeName

it's resolved and I got below solution -它已经解决了,我得到了以下解决方案 -

var result = 
(from l in db.Employees 
 join p in db.docs.Where(j => j.CompanyId == 1 && j.TaxYear == 2015) 
 on l.EmployeeId equals p.EmployeeId into temp    
 where l.CompanyId == 1
    select new 
      { EmployeeId =  l.EmployeeId, 
        EmployeeName = l.EmployeeName 
 }).Distinct().OrderBy(X => X.EmployeeName).ToList();
ViewSapIqosGdpF8
    .Where(x=>x.Claim.TblFieldClaimsHarmonized)
    .Any(y=>y.Vclaim.ViewFieldClaimsHarmonized)
    .Select(x=>x)

Where Claim and Vclaim are References of Foreign Keys其中 Claim 和 Vclaim 是外键的引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM