Reputation: 29
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
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