T-SQL:無法將T-SQL INNER JOIN到LINQ,查詢實體
declare @postlocations table (locationid int)
insert into @postlocations
select locationid
from dbo.PostLocations
where PostId = 162172
select t.*
from dbo.Themes t
inner join dbo.ThemeLocations tl on t.ThemeId = tl.ThemeId
inner join @postlocations pl on tl.LocationId = pl.locationid
LINQ的實體,我至今:
var postLocations = e.SomePost.Locations; // pre-fetched, e.g materialized ICollection<Post>
var themes = (from t in db.Themes
join q in postLocations on t.Locations.Select(l => l.LocationId) equals q.LocationId
select t).ToList();
但是,編譯器是抱怨的join
關鍵字不能推斷出類型參數。
任何想法?
爲什麼你的T-SQL兩個獨立查詢開始?它看起來應該是一個單一的查詢。 – 2012-04-11 06:51:19
@Damien_The_Unbeliever - 因爲第一個實際上是一個內存集合。相同的源數據,但已經預取。 – RPM1984 2012-04-11 08:07:08