Why does automapper create empty instances of collections if they are null? Here is my configuration
public class MapperProfile : Profile
{
protected override void Configure()
{
AllowNullCollections = true;
AllowNullDestinationValues = true;
Mapper.CreateMap<User, DAL.Models.User>();
Mapper.CreateMap<DAL.Models.User, User>();
Mapper.CreateMap<Role, DAL.Models.Role>();
Mapper.CreateMap<DAL.Models.Role, Role>();
Mapper.CreateMap<Task, DAL.Models.Task>();
Mapper.CreateMap<DAL.Models.Task, Task>();
Mapper.CreateMap<TaskReport, DAL.Models.TaskReport>();
Mapper.CreateMap<DAL.Models.TaskReport, TaskReport>();
Mapper.CreateMap<Project, DAL.Models.Project>();
Mapper.CreateMap<DAL.Models.Project, Project>();
}
}
My models have the same properties:
public class User
{
public virtual List<Task> Tasks { get; set; }
public virtual List<Role> Roles { get; set; }
public virtual List<TaskReport> TaskReports { get; set; }
}
In my MVC project in Global.asax I'm just add my profile like this:
Mapper.AddProfile(new BL.MapperProfile());
Thanks!