我正在尝试使用Entity Framework 6更新实例。我想这是一个断开连接的场景。更新失败-没有错误,但我更改的属性未保存在DB中。
控制器中的方法
var managers = _iManagerRepository.Managers.ToList();
var manager = managers.FirstOrDefault(m => m.Id == currentUserId);
if (manager != null)
{
manager.ContactDetail.FirstName = withTokenDto.managerInfoModel.FirstName;
manager.ContactDetail.SecondName = withTokenDto.managerInfoModel.SecondName;
manager.ContactDetail.LastName = withTokenDto.managerInfoModel.LastName;
_iManagerRepository.UpdateManager(manager);
return ResponseMessage(Request.CreateResponse(HttpStatusCode.OK));
}
存储库中的方法:
public void UpdateManager(Manager manager)
{
using (LightCRMEntities context = new LightCRMEntities())
{
context.Managers.Attach(manager);
context.Entry<Manager>(manager).State = EntityState.Modified;
context.SaveChanges();
}
}