【发布时间】:2015-12-04 03:40:36
【问题描述】:
简介:
public class StudentProfile : Profile
{
protected override void Configure()
{
Mapper.CreateMap<Student, StudentIndexModel>();
}
}
以及它中断的行:
public ActionResult Index()
{
// Breaks here
var students = Mapper.Map<IEnumerable<StudentIndexModel>>(db.Students.ToList());
return View(students);
}
当它从数据库中获取记录时,我遇到了一个不受支持的映射异常。没有返回记录时也不例外(表没有记录)
错误
缺少类型映射配置或不支持的映射。
映射类型: 学生 -> StudentIndexModel ContosoUniversity.Models.Student -> ContosoUniversity.ViewModels.StudentIndexModel
目标路径: IEnumerable`1[0]
学生班级:
public class Student : Entity
{
public Student() { }
public string LastName { get; set; }
public string Forenames { get; set; }
public DateTime EnrolmentDate { get; set; }
public virtual ICollection<Enrolment> Enrolments { get; set; }
}
还有 StudentIndexModel 类:
public class StudentIndexModel
{
public int Id { get; set; }
public string LastName { get; set; }
public string Forenames { get; set; }
public DateTime EnrolmentDate { get; set; }
}
我哪里错了?
【问题讨论】:
标签: c# automapper