我正在尝试构建linq到实体查询。这就是我到目前为止所做的:
from x in db.BusSchedule
join y in db.BusSchedule on x.ID equals y.ID - 1
where Convert.ToInt32(y.StopOrder) >= Convert.ToInt32(x.StopOrder)
&& x.NameOfTown == arrival
&& x.Line in (SELECT Line FROM BusSchedule WHERE NameOfTown = destination)
orderby x.DepartureTime ascending
select x).Distinct()
我不知道如何做IN部分,我正在粘贴我正在使用的实际sql查询。 我该如何翻译那个sql查询
'SELECT Line FROM BusSchedule WHERE NameOfTown = destination'
在Linq to Entities查询中?
提前致谢,Laziale
答案 0 :(得分:0)
var dest = (from b in db.BusSchedule
where b.NameOfTown = destination
select b.Line).ToList();
var output = (from x in db.BusSchedule.Where(b => b.NameOfTown == arrival)
join y in db.BusSchedule on x.ID equals y.ID - 1
where Convert.ToInt32(y.StopOrder) >= Convert.ToInt32(x.StopOrder)
&& dest.Contains(x.Line)
orderby x.DepartureTime ascending
select x)
.Distinct()