Nhibernate Automapper无法更新数据库中的表

时间:2014-06-23 08:05:50

标签: asp.net-mvc-3 sql-server-2008 nhibernate automapper

//首先,我选择Employee来编辑和更新Employee //

的详细信息
[HttpGet]
public ActionResult Edit(int? employee_id)
{
    Mapper.CreateMap<AutoMapperDemo.employee, AutoMapperDemo.Models.employees>();//Mapping using AutoMapper
    var dbContext = new MyDBDataContext();
    var EmployeeDetails = dbContext.employees.FirstOrDefault(Employee => Employee.employee_id == employee_id);
    var Employees = Mapper.Map<AutoMapperDemo.employee, AutoMapperDemo.Models.employees>(EmployeeDetails);
    return View(Employees);
}

//要编辑的代码//

[HttpPost]
public ActionResult Edit(employees employee1)
{

    Mapper.CreateMap<AutoMapperDemo.employee, AutoMapperDemo.Models.employees>();  //Mapping using AutoMapper

    var dbContext = new MyDBDataContext();
    var EmployeeDetails = dbContext.employees.FirstOrDefault(Employee => Employee.employee_id == employee1.employee_id);            
    TryUpdateModel(EmployeeDetails);
    Mapper.Map<AutoMapperDemo.employee, AutoMapperDemo.Models.employees>(EmployeeDetails);                
    dbContext.SubmitChanges();    
    return RedirectToAction("Index");
}

0 个答案:

没有答案