gpt4 book ai didi

c# - 可查询作为子查询过滤另一个可查询的

转载 作者:行者123 更新时间:2023-11-30 14:39:54 24 4
gpt4 key购买 nike

我有一个多对多的关系(站点、类别、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;

我希望能够根据可查询的网站将过滤器应用于可查询的类别,这样我就可以拥有任何带有任何过滤器的类别以及另一个具有包含特定过滤器的网站的类别过滤器,就像这样:

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

我之前也提出过类似的问题,当时我也不需要过滤类别(here)

非常感谢,

最佳答案

你可能想要其中之一

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

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

取决于您的用例。

关于c# - 可查询作为子查询过滤另一个可查询的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5958848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com