views:

83

answers:

2

Hi,

I use C# 3.5 DotNet Framework and Linq.

I have 2 Views which have the same result-schema, but in linq that are different objects of course.

How can I convert List a to List b?

+3  A: 

You can create a new list of B's:

List<B> listOfB = listOfA.Select(a => new B {
                                                Foo = a.Foo,
                                                Bar = a.Bar,
                                                // etc...
                                            }).ToList();
Mark Byers
+2  A: 

When they have the same structure, try take a look at AutoMapper.

With AutoMapper you can do something like this:

Mapper.CreateMap<Source, Destination>();
List<Destination> listDest = Mapper.Map<Source[], List<Destination>>(sources);
asgerhallas