从join转换为对象

本文关键字:对象 转换 join | 更新日期: 2023-09-27 17:51:23

我有一个join,它返回一个三重对象的列表。我能不能转换成这个对象的列表?

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;

从join转换为对象

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

你可以这样做,创建tuple列表

 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();
c# 4.0中的元组类型