使用自动映射器映射两个类的错误

问题描述 投票:0回答:1

我在项目级别有两个类,我想用 Auto Mapper 映射它们,但出现映射错误,你能帮助我吗?

public class RegisterVm
{
    [Required]
    public string FirstName { get; set; }
    [Required]
    public string LastName { get; set; }
    [Required]
    public string Mobile { get; set; }
    [Required]
    public string UserName { get; set; }
    [Required]
    [DataType(DataType.Password)]
    public string Password { get; set; }
}

public class RegistrationRequest
{
    [Required]
    public string FirstName { get; set; }
    [Required]
    public string LastName { get; set; }
    [Required]
    public string Mobile { get; set; }
    [Required]
    public string UserName { get; set; }
    [Required]
    [DataType(DataType.Password)]
    public string Password { get; set; }
}

收到错误

Error Image

我使用以下代码进行映射,但出现错误

CreateMap<RegisterVm, RegistrationRequest>().ReverseMap();
c# mapping automapper
1个回答
0
投票

删除ReverseMap()并编写类似以下的代码:

创建地图();

© www.soinside.com 2019 - 2024. All rights reserved.