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

标签 c# .net linq iqueryable

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

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/

相关文章:

c# - 文件夹上的 Filesystemwatcher 并获取文件名

.net - 将 Angular 模板 Web 应用程序添加到 Azure Service Fabric 集群?

c# - 阅读 .Net 堆栈跟踪

c# - 表达式树依赖分析器

c# - 如何在 lambda 表达式或 linq 中编写以下代码?

c# - Linq GroupJoin 与 Linq All in Select 的效率对比

c# - 提取版本号

C#和HtmlAgilityPack编码问题

javascript - Asp.Net core Vue C# + JS动态添加输入文本框

c# - 第三方 DLL 没有 'strong name'?