I am developing an MVC 3 application and am using AutoMapper to move data between my ViewModels and my entities. I have a scenario where I need to move data between two lists. For some strange reason, AutoMapper seems to only copy the first object from the source object and then seems to copy the same object n times over to the destination list. For example, say you have 2 lists, source contains six entity items and destination contains 0 items as it was just instantiated. The item at position source[0] get copied over to the destination and then source[0] is copied repeatedly for the same number of items there are in the source List, in this case 6. I don't understand what could be the cause of this.
Here is the AutoMapper configuration file:
public static class AutoMapperConfigurator
{
public static void Configure()
{
Mapper.CreateMap<User, UserModel>();
Mapper.CreateMap<Posting, PostingModel>();
}
}
Here is the Global.asax file setting
protected void Application_Start()
{
AutoMapperConfigurator.Configure();
}
Here is the location where I am calling the Map method
userSearchModel.UserList = Mapper.Map<IList<User>, IList<UserModel>>(userEntities);