Ejemplo n.º 1
0
 /// <summary>
 /// Asynchronously saves all changes made in this context to the underlying database.
 /// </summary>
 /// <param name="saveChangesAsync"></param>
 /// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
 /// <returns>
 /// A task that represents the asynchronous save operation.
 /// The task result contains the number of objects written to the underlying database.
 /// </returns>
 /// <remarks>
 /// Multiple active operations on the same context instance are not supported.  Use 'await' to ensure
 /// that any asynchronous operations have completed before calling another method on this context.
 /// </remarks>
 public async Task<int> SaveChangesAsync(Func<CancellationToken, Task<int>> saveChangesAsync, CancellationToken cancellationToken)
 {
     var hookExecution = new HookRunner(this);
     hookExecution.RunPreActionHooks();
     var result = await saveChangesAsync(cancellationToken);
     hookExecution.RunPostActionHooks();
     return result;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Asynchronously saves all changes made in this context to the underlying database.
        /// </summary>
        /// <param name="saveChangesAsync"></param>
        /// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
        /// <returns>
        /// A task that represents the asynchronous save operation.
        /// The task result contains the number of objects written to the underlying database.
        /// </returns>
        /// <remarks>
        /// Multiple active operations on the same context instance are not supported.  Use 'await' to ensure
        /// that any asynchronous operations have completed before calling another method on this context.
        /// </remarks>
        public async Task <int> SaveChangesAsync(Func <CancellationToken, Task <int> > saveChangesAsync, CancellationToken cancellationToken)
        {
            var hookExecution = new HookRunner(this);

            hookExecution.RunPreActionHooks();
            var result = await saveChangesAsync(cancellationToken);

            hookExecution.RunPostActionHooks();
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Saves all changes made in this context to the underlying database.
        /// </summary>
        /// <returns>
        /// The number of objects written to the underlying database.
        /// </returns>
        public int SaveChanges(Func <int> saveChanges)
        {
            var hookExecution = new HookRunner(this);

            hookExecution.RunPreActionHooks();
            var result = saveChanges();

            hookExecution.RunPostActionHooks();
            return(result);
        }