【问题标题】:Linq - How do I coalesce these into a single IQueryable?Linq - 我如何将这些合并成一个 IQueryable?
【发布时间】:2012-09-12 02:10:36
【问题描述】:

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

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

在我的代码的其他地方,我从数据库中检索IQueryable&lt;Thing&gt; things

我的目标是将things 中的所有strings 合并为一个IQueryable&lt;string&gt; strings,可能类似于:

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

但这只会给我一个IQueryable&lt;IList&lt;string&gt;&gt;。如何将所有这些列表合并到一个包罗万象的集合中?

【问题讨论】:

    标签: c# .net linq iqueryable


    【解决方案1】:

    尝试使用类似的东西:

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

    【讨论】:

    • 简单——却又如此难以捉摸。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    相关资源
    最近更新 更多