我有闲置的 SQL-Select:
select * from tlieferschein l
inner join tbestellung b on l.kbestellung = b.kbestellung
inner join tkunde k on b.tkunde_kkunde = k.kkunde
where b.nStorno = 0
and (select count(*) from tlieferscheinpos x inner join tbestellpos y on x.kbestellpos = y.kbestellpos and x.klieferschein = l.klieferschein) > 0
and b.cBestellNr = '718'
order by l.derstellt desc
现在,我应该将此 sql-select 转换为 linq。我已经尝试过休耕,但它不起作用:
var result = from l in context.tLieferschein
join b in context.tbestellung on l.kBestellung equals b.kBestellung
join k in context.tkunde on b.tKunde_kKunde equals k.kKunde
where b.nStorno == 0 && (from x in context.tLieferscheinPos join y in context.tbestellpos on x.kBestellPos equals y.kBestellPos && x.kLieferschein equals l.kLieferschein ).Count() > 0
orderby l.dErstellt descending
select new {l, b, k};
我希望有人可以帮助我,我做错了什么。
这是我第一次尝试为实体框架编写一个 Linq-Query。