简体   繁体   中英

How to do a subselect using linq method syntax

How can i do a subselect linq using method syntax, i had tried to google, but no luck. This is my sql query:

select * from dwvtextures where id in (select TextureId from dwvtexturetag where TagId = 2)
var idList = dwvtexturetag.Select(x => x.TextureId).Where(x => x.TagId = 2);

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

With the query syntax:

from d in dwvtextures
where (from x in dwvtexturetag
       where x.TagId = 2
       select x.TextureId).Contains(d.Id)
select d;
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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM