我试图将SQL语句转换为LINQ,由于某种原因,我得到的结果集是不同的。 SQL返回的数据多于LINQ。
这是SQL查询:
SELECT DISTINCT ssLookup.StopID,
dc.CityName,
dc.StateAbbrev,
sc.CarrierID,
sc.CarrierCode,
sc.CarrierName
FROM ScheduleDestinationCache dc
INNER JOIN ScheduleStops ssFilter ON ssFilter.CarrierID = dc.CarrierID
INNER JOIN ScheduleStops ssLookup ON dc.CityID = ssLookup.StopID
INNER JOIN ScheduleCarriers sc ON ssLookup.CarrierID = sc.CarrierID
WHERE (ssFilter.StopID = 582 OR ssFilter.StopID IN
(SELECT * FROM dbo.GetTwins(582)))
ORDER BY dc.CityName, dc.StateAbbrev
这是LINQ声明:
(from sdc in ScheduleDestinationCaches
let twins = GetTwins(582).Select(gt => gt.StopIDs)
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 ssFilter.StopID == 582 || twins.Contains(ssFilter.StopID)
orderby sdc.CityName, sdc.StateAbbrev
select new {
ssLookup.StopID,
sdc.CityName,
sdc.StateAbbrev,
sc.CarrierID,
sc.CarrierCode,
sc.CarrierName
}).GroupBy(g => new
{
g.StopID,
g.CityName,
g.StateAbbrev,
g.CarrierID,
g.CarrierCode,
g.CarrierName
})
我做错了什么?
提前谢谢。