/// <summary>
 ///     Saves the updated entities into the actual database.
 /// </summary>
 /// <returns>
 ///     The save operation result which can either be
 ///     a SaveChangesResult.Success or SaveChangesResult.Error.
 /// </returns>
 public SaveChangesResult SaveChanges()
 {
     try
     {
         return(SaveChangesResult.Success(this.dbContext.SaveChanges(), this.Entries));
     }
     catch (DbUpdateException e)
     {
         return(SaveChangesResult.Error(e, this.Entries));
     }
 }
 /// <summary>
 ///     Asynchronously saves the updated entities into the actual database.
 /// </summary>
 /// <param name="cancellationToken">
 ///     A <see cref="CancellationToken" /> to observe while waiting for the task to
 ///     complete.
 /// </param>
 /// <returns>
 ///     A task that represents the asynchronous operation.
 ///     The task result contains the save operation result which can either be
 ///     a SaveChangesResult.Success or SaveChangesResult.Error.
 /// </returns>
 public async Task <SaveChangesResult> SaveChangesAsync(CancellationToken cancellationToken = default)
 {
     try
     {
         return(SaveChangesResult.Success(await this.dbContext.SaveChangesAsync(cancellationToken), this.Entries));
     }
     catch (DbUpdateException e)
     {
         return(SaveChangesResult.Error(e, this.Entries));
     }
 }
示例#3
0
 public SaveChangesResult Commit()
 {
     try
     {
         _context.SaveChanges();
         return(SaveChangesResult.Success());
     }
     catch (Exception)
     {
         return(SaveChangesResult.Failed());
     }
 }