使用Auto Mapper将视图模型映射到域中的对象

时间:2016-06-18 18:37:04

标签: automapper

public class Department
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
}

public class Employee
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual Department department { get; set; }
}

public class vmEmployeeDepartment
{
    public int EmployeeId { get; set; }
    public string EmployeeName { get; set; }
    public int DepartmentID { get; set; }
    public string DepartmentName { get; set; }
}

我想将vmEmployeeDepartment映射到Empolyee

public JsonResult Add(vmMuasher vm)
{
    var model = Mapper.Map<vmEmployeeDepartment, Empolyee>(vm);
    _EmployeeService.Add(model);

    return Json(vm, JsonRequestBehavior.AllowGet);
}

问题是:Emplyee域内的Department对象为null,

如何解决此问题?

0 个答案:

没有答案
相关问题