gpt4 book ai didi

c# - Linq - 如何将它们合并到一个 IQueryable 中?

转载 作者:行者123 更新时间:2023-12-02 22:29:44 38 4
gpt4 key购买 nike

我有一个简单的(混淆的)类:

public Thing ()
{
public IList<string> Strings()
{
// returns an IList of whatever,
// using strings as an example
}
}

在我的代码的其他地方,我检索了一个 IQueryable<Thing> things来自数据库

我的目标是获得所有 string来自 things合二为一IQueryable<string> strings ,也许是这样的:

var strings = from t in things
select t.Strings()

但这只会给我一个 IQueryable<IList<string>> .如何将所有这些列表合并成一个包罗万象的集合?

最佳答案

尝试使用类似的东西:

things.SelectMany(t => t.Strings);

关于c# - Linq - 如何将它们合并到一个 IQueryable 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12500280/

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