从连接转换为对象

时间:2013-01-10 10:29:10

标签: c# .net linq

我有连接,它返回一个三重对象的列表。我可以以某种方式转换为这些对象的列表吗?

var result = entities.Join(...).Join(...).Join(.. new {a=a, b=b, c=c}).ToList();
//how to cast like:
var multipleList = (List<{ObjectA, ObjectB, ObjectC}>)result;

2 个答案:

答案 0 :(得分:2)

var multipleList = 
    result.SelectMany(x => new object[] { x.a, x.b, x.c })
          .ToList();

答案 1 :(得分:1)

你可以这样做,创建元组列表

 var data = (from e in entities
             ///code to join entities...
            select new Tuple<ClassA, ClassB, ClassC>
                (
                     e1,//enitry of ClassA
                     e2,//enitry of ClassB
                     e3//enitry of ClassC
                 )).ToList();

在此处阅读元组:Tuple Type in C#4.0