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