You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code from the UnitOfWork class assume that there were be a non zero result from the SaveChangesAsync method;
publicasyncTask<bool>Save(CancellationTokentoken){try{returnawait_context.SaveChangesAsync(token)>0;}catch(Exceptionex){_logger.LogError(ex,"UnitOfWork failed to save changes");returnfalse;}}
this is an invalid assumption - SaveChangesAsync only returns a positive number when there are rows inserted (i.e. an addition) for updates the value will be zero.
The code should be as follows instead;
publicasyncTask<bool>Save(CancellationTokentoken){try{await_context.SaveChangesAsync(token);returntrue;}catch(Exceptionex){_logger.LogError(ex,"UnitOfWork failed to save changes");returnfalse;}}
To see a live example of this bug look at MovieRepository.SaveMovie in the Movies repo;
This code from the UnitOfWork class assume that there were be a non zero result from the SaveChangesAsync method;
this is an invalid assumption - SaveChangesAsync only returns a positive number when there are rows inserted (i.e. an addition) for updates the value will be zero.
The code should be as follows instead;
To see a live example of this bug look at MovieRepository.SaveMovie in the Movies repo;
the final line returns false on edits.
The text was updated successfully, but these errors were encountered: