Indra H
Indra H

Reputation: 29

Automapper from list of object

I have View Model and Class that I have to map. This is my maping setting:

Mapper.CreateMap<ViewModels.objTest, clsTest>().ReverseMap();

I have to map List of View model to my clsTest.

for now I'm using looping like this:

List<clsTest> objListResult = new List<clsTest>();
if (List<objTest> != null)
{
    foreach (var item in objTest)
    {
        objListResult.Add(Mapper.Map<objTest, clsTest>(item));
    }
}

Its work fine, but is there anyway to map faster than this? Maybe is there any way mapping from List to List even my setting like above?

Thank you

Upvotes: 1

Views: 1830

Answers (1)

Milney
Milney

Reputation: 6427

You can just call Map with the list...

List<objTest> objListResult = Mapper.Map<List<clsTest>, List<objTest>>(objTest);

As you can see in documentation: http://automapper.codeplex.com/wikipage?title=Lists%20and%20Arrays

Upvotes: 3

Related Questions