如何在linq中编写SQL查询

时间:2013-11-06 06:14:29

标签: sql linq

有人可以告诉我如何在SQL中撰写以下linq查询:

SELECT approvaldate, issubmitted, companyemail, * 
FROM registrations r 
WHERE (r.issubmitted = 'true')
  AND (r.approvaldate IS NULL) 
  AND (companyemail LIKE '%gmail%' 
       OR companyid IN (SELECT companyid FROM companies 
                        WHERE companyname LIKE '%gmail%')
      ) 

由于

2 个答案:

答案 0 :(得分:0)

请尝试使用以下代码段。 (如果有任何疑虑,请告诉我,因为我没有测试过查询)

var query = (from r in registrations
             Where r.issubmitted  = true 
                   && r.approvaldate.HasValue == false
                   && ( 
                        r.companyemail.IndexOf("gmail") >= 0
                       ||
                         companies.Any(c => c.companyid  == r.companyid  && c.companyname.IndexOf("gmail") >= 0)
                       )     
             select r).ToList();

请查看以下链接以供参考

http://csharp-guide.blogspot.in/2012/05/linq-to-sql-sub-queries.html

答案 1 :(得分:0)

var query = registrations.Where(x=>
                x.issubmitted &&
                x.approvaldate == null &&
                (
                    companyemail.Contains("gmail") ||
                    companies.Any(y => y.companyid  == x.companyid &&
                                       y.companyname.Contains("gmail"))
                ));