查询linq中没有任何内容

时间:2014-01-25 21:29:12

标签: linq ef-code-first

我正在尝试将sql转换为linq,但我的查询中没有得到任何结果。 我的sql:

select e.FirstAired, s.SeriesName, e.EpisodeNr, e.SeasonNr
from series s 
join LaastGedownloads l on s.SeriesID = l.SeriesID
join Episodes e on e.SeriesID = l.SeriesID
where e.EpisodeNr = l.LastEpisode
and e.SeasonNr = l.LastSeason

My Linq

SerieContext sc = new SerieContext();
List<Serie> ds=sc.series.Include("Episodes").Include("LaastGedownload").ToList();
var query = (from s in sc.series
             join l in sc.LaastGedownload on s.SeriesID equals l.SeriesID
             join e in sc.Episodes on l.SeriesID equals e.SeasonID
             where e.EpisodeNr == l.LastEpisode
                   && e.SeasonNr == l.LastSeason
             select s).ToList();

My VS2013 solution zip

1 个答案:

答案 0 :(得分:1)

加入剧集时,您使用的是SeasonID而不是SeriesID

join e in sc.Episodes on l.SeriesID equals e.SeasonID

但是在你的SQL中

join Episodes e on e.SeriesID = l.SeriesID