Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,24 @@ public virtual async Task<T> AddAsync(T entity, CancellationToken cancellationTo

return entity;
}
/// <inheritdoc/>
public virtual async Task<IEnumerable<T>> AddRangeAsync(IEnumerable<T> entities, CancellationToken cancellationToken = default)
{
dbContext.Set<T>().AddRange(entities);

await SaveChangesAsync(cancellationToken);

return entities;
}

/// <inheritdoc/>
public virtual async Task UpdateAsync(T entity, CancellationToken cancellationToken = default)
{
dbContext.Entry(entity).State = EntityState.Modified;

await SaveChangesAsync(cancellationToken);
}

/// <inheritdoc/>
public virtual async Task DeleteAsync(T entity, CancellationToken cancellationToken = default)
{
Expand All @@ -55,6 +66,7 @@ public virtual async Task DeleteRangeAsync(IEnumerable<T> entities, Cancellation

await SaveChangesAsync(cancellationToken);
}

/// <inheritdoc/>
public virtual async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,24 @@ public virtual async Task<T> AddAsync(T entity, CancellationToken cancellationTo

return entity;
}
/// <inheritdoc/>
public virtual async Task<IEnumerable<T>> AddRangeAsync(IEnumerable<T> entities, CancellationToken cancellationToken = default)
{
dbContext.Set<T>().AddRange(entities);

await SaveChangesAsync(cancellationToken);

return entities;
}

/// <inheritdoc/>
public virtual async Task UpdateAsync(T entity, CancellationToken cancellationToken = default)
{
dbContext.Set<T>().Update(entity);

await SaveChangesAsync(cancellationToken);
}

/// <inheritdoc/>
public virtual async Task DeleteAsync(T entity, CancellationToken cancellationToken = default)
{
Expand All @@ -55,6 +66,7 @@ public virtual async Task DeleteRangeAsync(IEnumerable<T> entities, Cancellation

await SaveChangesAsync(cancellationToken);
}

/// <inheritdoc/>
public virtual async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
{
Expand Down
10 changes: 10 additions & 0 deletions Specification/src/Ardalis.Specification/IRepositoryBaseOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public interface IRepositoryBase<T> : IReadRepositoryBase<T> where T : class
/// </returns>
Task<T> AddAsync(T entity, CancellationToken cancellationToken = default);
/// <summary>
/// Adds the given entities in the database
/// </summary>
/// <param name="entities"></param>
/// <param name="cancellationToken"></param>
/// <returns>
/// A task that represents the asynchronous operation.
/// The task result contains the <typeparamref name="IEnumerable<T>" />.
/// </returns>
Task<IEnumerable<T>> AddRangeAsync(IEnumerable<T> entities, CancellationToken cancellationToken = default);
/// <summary>
/// Updates an entity in the database
/// </summary>
/// <param name="entity">The entity to update.</param>
Expand Down