Marcin M
Marcin M

Reputation: 375

Cast to object from join

i have join which returns a list of an triple objects. Can I somehow cast to list of this objects?

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;

Upvotes: 2

Views: 116

Answers (2)

Douglas
Douglas

Reputation: 54897

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

Upvotes: 2

Pranay Rana
Pranay Rana

Reputation: 176946

you can do like this, create list of 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();

Read about tuple here : Tuple Type in C#4.0

Upvotes: 1

Related Questions