开发者

Automaper how to map this?

I tried to do this

public class TaskTableViewModel
{
    public string CourseCoursePermissionsBackgroundColor { get; set; }
}

 public class Course
{
    public virtual IList<CoursePermission> CoursePermis开发者_JAVA技巧sions { get; set; }

    public Course()
    {
        CoursePermissions = new List<CoursePermission>();
    }
}

    public class CoursePermission
{
    public virtual string BackgroundColor { get; set; }

}

So I am trying to get BackgroundColor into the viewModel but I can't figure it out as it is in a list.

List<Task> tasks = taskService.GetAllTasks("email@gmail.com");

    List<TaskTableViewModel> viewModel = new List<TaskTableViewModel>();
    List<TaskTableViewModel> taskViewModelList = new List<TaskTableViewModel>();

    viewModel = Mapper.Map<List<Task>, List<TaskTableViewModel>>(tasks);

This is what I am trying to do.

  taskViewModelList[i].CourseCoursePermissionsBackgroundColor = tasks[i].Course.CoursePermissions.BackgroundColor 

the above would get me the access to the color. So in the end Task and taskTableViewModel should have the same number in each collection.


First create

Mapper.CreateMap<Task,TaskTableViewModel>()
             .ForMember(dest => dest.CourseCoursePermissionsBackgroundColor,
                         opt => opt.MapFrom(src=>src.Course.CoursePermissions[0].BackgroundColor));

And then try the Mapper.Map you have

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜