Как я могу достичь этого с помощью automapper?
I have an index view that routes to the details view for each student via StudentId. The details view displays a partial view of the student's course information (also routed via StudentId). The course information currently comes from two tables: StudentCourse and StudentCoursePast. I would like to map a third table - Course - so I can get the corresponding CourseTitle for each CourseId in my StudentCourseViewModel. With the code below, I am able to get the correct data from both studentCourse and StudentCoursePast tables. However, all my attempts to map the Course table so I can get the CourseTitle field in my view has been futile.Please help!
Что я уже пробовал:
Student public string StudentId public string Name StudentCourse public string StudentId public string Courseid public string Room public DateTime Date StudentCoursePast public string StudentId public string CourseId public string Room public DateTime Date Courses Public string CourseId Public string CourseTitle StudentCourseViewModel public string Courseid public string CourseTitle public string Room public DateTime Date AutoMapperProfile CreateMap<StudentCourse, StudentCourseViewModel> CreateMap<StudentCoursePast, StudentCourse> CreateMap<Course, StudentCourseViewModel>.ForMember(dest => dest.Courseid, opts => opts.MapFrom(src => src.CourseId)); StudentController var course = _context.StudentCourses.Where (s => s.StudentId == student.StudentId).ToList(); var coursePast = _context.StudentCoursesPast.Where (s => s.StudentId == student.StudentId).ToList(); var studentCourse = course.Union(_mapper.Map<List<StudentCoursePast>, List<StudentCourse>>(coursePast)).ToList(); model.StudentCourse=_mapper.Map<IList<StudentCourse>, IList<StudentCourseViewModel>>(studentCourse);