0

谁能告诉我如何编写以下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%')
      ) 

谢谢

4

2 回答 2

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

于 2013-11-06T06:51:43.947 回答
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"))
                ));
于 2013-11-08T23:11:48.010 回答