简体   繁体   English

Iqueryable作为子查询来过滤另一个iqueryable

[英]Iqueryable as a subquery to filter another iqueryable

I have a many to many relationship (Sites, Categories, CategoriesXSite) and two iqueryable defined variables like this: 我有很多关系(Sites,Categories,CategoriesXSite)和两个可以定义的变量,如下所示:

IQueryable<Site> sitesQuery = from s in db.Sites
                         where s.Name.Contains(siteWord)
                         select s



IQueryable<SiteCategorie> categoriesQuery = from c in db.SiteCategories
                                       where c.Parent.ID == 1
                                       select c;

I want to be able to apply a filter to categories iqueryable based on sites iqueryable so that way I can have any categories with any filters plus another filter of the categories that has sites containing certain filter, some thing like this: 我希望能够根据可查询的网站将过滤器应用于iqueryable类别,这样我就可以使用任何过滤器以及包含某些过滤器的网站的类别的另一个过滤器,这样的一些事情:

from c in categoriesQuery 
where c.Sites == sitesQuery
select c

I've made a similar question before when I didn't need to filter categories as well ( here ) 我以前也提出了类似的问题,当时我不需要过滤类别( 这里

Thanks a lot, 非常感谢,

You'll probably want either 你可能也想要

from c in categoriesQuery  
where c.Sites.Any(s => sitesQuery.Contains(s))
select c 

or 要么

from c in categoriesQuery  
where c.Sites.All(s => sitesQuery.Contains(s))
select c 

depending on your use case. 取决于您的使用案例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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