我有以下linq查询,它给出以下错误:查询正文必须以select子句或group子句结束
from sdc in ScheduleDestinationCaches
let twins = from gt in GetTwins(72)
join ssFilter in ScheduleStops on sdc.CarrierID equals ssFilter.CarrierID
join ssLookup in ScheduleStops on sdc.CityID equals ssLookup.CityID
join sc in ScheduleCarriers on ssLookup.CarrierID equals sc.CarrierID
where twins.Contains(ssFilter.StopID ) || ssFilter.StopID == 72
select sc
任何想法?
顺便说一句,我使用linqpad
答案 0 :(得分:0)
让我们添加一些缩进:
from sdc in ScheduleDestinationCaches
let twins = from gt in GetTwins(72)
join ssFilter in ScheduleStops on sdc.CarrierID equals ssFilter.CarrierID
join ssLookup in ScheduleStops on sdc.CityID equals ssLookup.CityID
join sc in ScheduleCarriers on ssLookup.CarrierID equals sc.CarrierID
where twins.Contains(ssFilter.StopID ) || ssFilter.StopID == 72
select sc
你现在能看到这个问题吗?将from
作为赋值添加到let
- 已定义的变量将启动新的LINQ表达式,该表达式以select sc
结尾。这使得外部查询根本没有select
子句!
我认为你正在寻找
from sdc in ScheduleDestinationCaches
let twins = GetTwins(72)
join ssFilter in ScheduleStops on sdc.CarrierID equals ssFilter.CarrierID
join ssLookup in ScheduleStops on sdc.CityID equals ssLookup.CityID
join sc in ScheduleCarriers on ssLookup.CarrierID equals sc.CarrierID
where twins.Contains(ssFilter.StopID ) || ssFilter.StopID == 72
select sc
基于评论的更新
from sdc in ScheduleDestinationCaches
let twins = GetTwins(72).Select(x => x.Id)
join ssFilter in ScheduleStops on sdc.CarrierID equals ssFilter.CarrierID
join ssLookup in ScheduleStops on sdc.CityID equals ssLookup.CityID
join sc in ScheduleCarriers on ssLookup.CarrierID equals sc.CarrierID
where twins.Contains(ssFilter.StopID ) || ssFilter.StopID == 72
select sc