linq - 哪个查询表达式相当于以下 LINQ 查询?

标签 linq linq-to-objects

Possible Duplicate:
Can these two LINQ queries be used interchangeably?

var query =  from c_1 in collection_1
             select c_1.collection_2 into c_2
             select c_2.collection_3 into c_3
             select c_3;

相当于

  var query = collection_1
            .Select(c_1 => c_1.collection_2)
            .Select(c_2 => c_2.collection_3)
            .Select(c_3 => c_3);

a) 但是哪个查询表达式等效于以下 LINQ 查询:

var query = collection_1
            .Select(c_1 => c_1.collection_2
            .Select(c_2 => c_2.collection_3.Select(c_3 => new { c_1, c_2, c_3 } )));

谢谢

最佳答案

var query = from c_1 in collection_1
            select from c_2 in c_1.collection_2
                   select from c_3 in c_2.collection_3
                          select  new { c_1, c_2 c_3 };

关于linq - 哪个查询表达式相当于以下 LINQ 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13018026/

相关文章:

c# - 有没有一种聪明的方法来动态调用依赖于类型的扩展方法?

c# - Linq 延迟操作

.net - 通过非泛型 IDictionary 枚举时,无法将泛型字典项转换为 DictionaryEntry

c# - HashSet<T> 和 Linq 查询的性能

c# - LINQ 中的 OrderBy 和 Top 性能良好

c# - 如何返回 IQueryable<T>

c# - 如何使用 Linq to Entity 获取最大 ID?

c# - 如何使用 LINQ 将这些数据组织成我想要的对象?

c# - 使用 LINQ 断言数组的所有成员都是等效的?