Skip to content

Commit

Permalink
Predicate to ExecuteUpdateAsync addded.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanvir Ahmad Arjel authored and Tanvir Ahmad Arjel committed Dec 23, 2023
1 parent 7cddcdd commit 18cda12
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/TanvirArjel.EFCore.GenericRepository/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,28 @@ Task<int> ExecuteUpdateAsync<TEntity>(
CancellationToken cancellationToken = default)
where TEntity : class;

/// <summary>
/// Asynchronously updates database rows for the entity instances which match the
/// LINQ query from the database.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="condition">The condition on which records will be filtered to be updated.</param>
/// <param name="setPropertyCalls">A collection of set property statements specifying properties to update.</param>
/// <param name="cancellationToken">A System.Threading.CancellationToken to observe while waiting for the task to complete.</param>
/// <returns>The total number of rows updated in the database.</returns>
/// <remarks>
/// This operation executes immediately against the database, rather than being deferred
/// until Microsoft.EntityFrameworkCore.DbContext.SaveChanges is called. It also
/// does not interact with the EF change tracker in any way: entity instances which
/// happen to be tracked when this operation is invoked aren't taken into account,
/// and aren't updated to reflect the changes.
/// </remarks>
Task<int> ExecuteUpdateAsync<TEntity>(
Expression<Func<TEntity, bool>> condition,
Expression<Func<SetPropertyCalls<TEntity>, SetPropertyCalls<TEntity>>> setPropertyCalls,
CancellationToken cancellationToken = default)
where TEntity : class;

/// <summary>
/// Asynchronously deletes all the database rows for the specified entity instance.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/TanvirArjel.EFCore.GenericRepository/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ public async Task<int> ExecuteUpdateAsync<TEntity>(
return count;
}

public async Task<int> ExecuteUpdateAsync<TEntity>(
Expression<Func<TEntity, bool>> condition,
Expression<Func<SetPropertyCalls<TEntity>, SetPropertyCalls<TEntity>>> setPropertyCalls,
CancellationToken cancellationToken = default)
where TEntity : class
{
int count = await _dbContext.Set<TEntity>().Where(condition).ExecuteUpdateAsync(setPropertyCalls, cancellationToken);
return count;
}

public async Task<int> ExecuteDeleteAsync<TEntity>(CancellationToken cancellationToken = default)
where TEntity : class
{
Expand Down

0 comments on commit 18cda12

Please sign in to comment.