gpt4 book ai didi

linq-to-objects - 根据值过滤 linq 查找

转载 作者:行者123 更新时间:2023-12-05 00:38:59 27 4
gpt4 key购买 nike

我想根据其值过滤 linq 查找:

查找:

ILookup<int, Article> lookup

这是我到目前为止无法正常工作的内容:
IList<int> cityIndexes = GetCityIndexesByNames(cities);    

lookup = lookup
.Where(p => p.Any(x => cityIndexes.Contains((int)x.ArticleCity)))
.SelectMany(l => l)
.ToLookup(l => (int)l.ArticleParentIndex, l => l);

只是为了澄清:我想获取所有包含在上述城市索引列表中的城市索引的文章。

最佳答案

您发布的代码的问题在于,您获取的所有文章的 ID 与任何具有匹配城市索引的文章的 ID 相同。如果你只是先拆包,那没有问题。

IList<int> cityIndexes = GetCityIndexesByNames(cities);

lookup = lookup
.SelectMany(g => g)
.Where(article => cityIndexes.Contains((int)article.ArticleCity)))
.ToLookup(article => (int)article.ArticleParentIndex);

或者
lookup =
(
from g in lookup
from article in g
where cityIndexes.Contains((int)article.ArticleCity)))
select article
).ToLookup(article => (int)article.ArticleParentIndex);

关于linq-to-objects - 根据值过滤 linq 查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4950468/

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