C# 缺少映射配置,配置文件中映射的类
个人资料:C# 缺少映射配置,配置文件中映射的类,c#,automapper,C#,Automapper,个人资料: public class StudentProfile : Profile { protected override void Configure() { Mapper.CreateMap<Student, StudentIndexModel>(); } } 我哪里做错了?我又做了一次,两秒钟后我找到了我自己问题的答案 我在Global.asax中添加了以下内容: AutoMapperConfiguration.Configure
public class StudentProfile : Profile
{
protected override void Configure()
{
Mapper.CreateMap<Student, StudentIndexModel>();
}
}
我哪里做错了?我又做了一次,两秒钟后我找到了我自己问题的答案 我在Global.asax中添加了以下内容:
AutoMapperConfiguration.Configure();
其中AutomapperConfiguration
具有Mapper.Initialize()
方法
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; }
}
public class StudentIndexModel
{
public int Id { get; set; }
public string LastName { get; set; }
public string Forenames { get; set; }
public DateTime EnrolmentDate { get; set; }
}
AutoMapperConfiguration.Configure();