将sql转换为lambda表达式或Linq

时间:2014-02-18 10:27:13

标签: c# linq lambda

您好我有以下sql语句我想将其转换为lambda表达式或linq

select
a.lid
,a.name
,a.notes
,lrh.e
,lrh.date
from rate a 
left outer join lab_history lrh on(lrh.lab_id=a.lid)

请让我知道如何将其更改为lambda表达式或linq。谢谢

2 个答案:

答案 0 :(得分:1)

您可以使用此查询:

from a in db.rate
join lrh db.lab_history on a.lid equals lrh.lab_id 
into lrhs
from lrh in lrhs.DefaultIfEmpty()
select new 
   {
      lid = a.lid,
      ... another props
   }

答案 1 :(得分:0)

你可以尝试

   var labRateObj = (from a in ContextObj.rate 
       join lrh in ContextObj.lab_history on a.lid equals lrh.lab_id into labrate
       from s in labrate.DefaultIfEmpty()
    select new {
    lid = a.lid,
    name = a.name,
    notes = a.notes,
    e = lrh.e,
    date = lrh.date

    });