如何使用linq方法语法进行子选择

时间:2014-07-01 10:38:08

标签: c# linq

我如何使用方法语法进行subselect linq,我曾试图谷歌,但没有运气。这是我的SQL查询:

select * from dwvtextures where id in (select TextureId from dwvtexturetag where TagId = 2)

2 个答案:

答案 0 :(得分:2)

var idList = dwvtexturetag.Select(x => x.TextureId).Where(x => x.TagId = 2);

var result = dwvtextures.Where(d => idList.Contains(d.Id));

使用查询语法:

from d in dwvtextures
where (from x in dwvtexturetag
       where x.TagId = 2
       select x.TextureId).Contains(d.Id)
select d;

答案 1 :(得分:0)

var innerQuery = from dt in dwvtexturetag  where dt.TagId = 2 select dt.TagId;
var result = from f in dwvtextures where innerQuery.Contains(f.TagId) select f;