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();