哪个查询表达式等同于以下LINQ查询?

时间:2012-10-22 19:04:30

标签: linq linq-to-objects

  

可能重复:
  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 } )));

谢谢

1 个答案:

答案 0 :(得分:2)

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 };