我有连接,它返回一个三重对象的列表。我可以以某种方式转换为这些对象的列表吗?
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;
答案 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