我正在使用ASP.NET Web API 2,Code First,EF 6,MS SQL Developer Server,依赖注入– Autofac开发应用程序。该应用程序具有多个层-DAL,BLL和带有控制器等的Web层。 更新操作不是自然行为。 当我通过邮递员对其进行测试时,BLL层的Update / Put方法会接收到适当的Web查询,并且应该将其转移到DAL层,在DAL层中应在db中更新已更新的实体。更新不会保存到数据库。但是,当我调试查询并使用F10 / F11逐行浏览代码时,更新会完美地更新db中的实体。 也许某些机构可以帮助解决这个问题?
public async Task<bool> Update(CustomerNotificationDTM cNotificationDtm) //BLL layer method
{
try
{
CustomerNotification customerNotification = new CustomerNotification();
customerNotification.EmployeeId = cNotificationDtm.EmployeeId;
customerNotification.AfterBooked = cNotificationDtm.AfterBooked;
customerNotification.AfterRescheduled = cNotificationDtm.AfterRescheduled;
customerNotification.AfterCancelled = cNotificationDtm.AfterCancelled;
if(cNotificationDtm.Employee != null)
customerNotification.Employee = ModelFactory.changeFromDTM(cNotificationDtm.Employee);
return await Database.CustomerNotifications.Update(customerNotification) ? true : false;
}
catch (Exception ex) { return false; }
}
public async Task<bool> Update(CustomerNotification notification) // DAL Layer Update method called from BLL
{
try
{
var initialNotification = await db.CustomerNotifications.FindAsync(notification.EmployeeId);
if (initialNotification != null)
{
initialNotification.AfterBooked = notification.AfterBooked;
initialNotification.AfterRescheduled = notification.AfterRescheduled;
initialNotification.AfterCancelled = notification.AfterCancelled;
await db.SaveChangesAsync();
return true;
}
}
catch (Exception ex) { return false;}
}