如何使用AutoMapper创建从单个类到嵌套类的映射

时间:2019-10-22 14:40:55

标签: automapper

我的班级结构看起来像这样。我想做的是,创建从源EmployeeInfo类到目标NewEmployeeInfo类的自动映射,然后使用Versa。

public class EmployeeInfo ///// Old Employee class - Transform this into New
{
    public int EmployeeID { get; set; }
    public string EmployeeName { get; set; }
    public int DepartmentID { get; set; }
    public string DepartmentName { get; set; }
}

public class NewEmployeeInfo //// New Employee -- Transform in to this
{
    public Employee Employee { get; set; }
    public Department Department { get; set; }
}

public class Employee
{
    public int EmployeeID { get; set; }
    public string EmployeeName { get; set; }
}

public class Department
{
    public int DepartmentID { get; set; }
    public string DepartmentName { get; set; }
}

0 个答案:

没有答案