簡體   English   中英

linq to entity 查詢,它有多個 where 子句和一個 where 子句,條件為 where

[英]linq to entities query which has multiple where clause and one where clause with where in condition

我正在嘗試構建一個 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 = 目的地'

在 Linq to Entities 查詢中?

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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM