Home:ALL Converter>SaveChangesAsync() method not updating database

SaveChangesAsync() method not updating database

Ask Time:2018-06-08T22:11:45         Author:Régis NIOX

Json Formatter

I have a web application with:

  • Entity Framework 6.1.3
  • Framework .NET 4.5.1

I made an upgrade of .NET Framework from version 4.5.1 to 4.6.2.

Since that, the "SaveChangesAsync()" of "System.Data.Entity" method does not updating my database anymore.

I can not find if it's because of the .NET framework package or some compatibility issues between Entity Framework 6.1.3 and .NET Framwork 4.6.2 for "SaveChangesAsync()" method... I'm a lost!

Here's some samples:

Service class

public async Task<MyActionResponseModel> UpdateSomething(Catalogue catalogue)
    if (catalogue== null) throw new ArgumentNullException("catalogue is null");
    var response = new ActionAddResponse();

    var catalogueToUpdate = await _catalogueRepository.GetCatalogueById(catalogue.Id);
    var myDate = new DateTime();
    if (catalogue.EndDate != null)
        myDate = catalogue.EndDate.Value;
        myDate = myDate.Date.AddHours(23).AddMinutes(59);

    catalogueToUpdate.Year = catalogue.Year;
    catalogueToUpdate.StartDate = catalogue.StartDate;
    catalogueToUpdate.EndDate = catalogue.EndDate!= null ? myDate : catalogue.EndDate;
    catalogueToUpdate.Tax = catalogue.Tax;
    catalogueToUpdate.Online = Convert.ToBoolean(catalogue.Online);
    catalogueToUpdate.RefNote = catalogue.RefNote;

    await _unitOfWork.SaveAsync();

    response.Success = true;
    response.Message = string.Format("Catalogue has been update");

    return response;

UnitOfWork class

public class UnitOfWork:IUnitOfWork
    public async Task SaveAsync()
        await _context.SaveChangesAsync(); // System.Data.Entity


  <package id="EntityFramework" version="6.1.3" targetFramework="net462" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.6" targetFramework="net451" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.6" targetFramework="net451" />
  <package id="Newtonsoft.Json" version="10.0.1" targetFramework="net451" />

I already checked my async/await choregraphy and everything seems correct. So what is happening right there?

Thank you in advance.

Author:Régis NIOX,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50762560/savechangesasync-method-not-updating-database