Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Repository DeleteAsync and DeleteManyAsync methods #7543

Merged
merged 6 commits into from
Feb 2, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public interface IRepository<TEntity> : IReadOnlyRepository<TEntity>, IBasicRepo
{
/// <summary>
/// Get a single entity by the given <paramref name="predicate"/>.
/// It returns null if no entity with the given <paramref name="predicate"/>.
/// <para>
/// It returns null if there is no entity with the given <paramref name="predicate"/>.
/// It throws <see cref="InvalidOperationException"/> if there are multiple entities with the given <paramref name="predicate"/>.
/// </para>
/// </summary>
/// <param name="predicate">A condition to find the entity</param>
/// <param name="includeDetails">Set true to include all children of this entity</param>
Expand All @@ -34,8 +36,10 @@ public interface IRepository<TEntity> : IReadOnlyRepository<TEntity>, IBasicRepo

/// <summary>
/// Get a single entity by the given <paramref name="predicate"/>.
/// <para>
/// It throws <see cref="EntityNotFoundException"/> if there is no entity with the given <paramref name="predicate"/>.
/// It throws <see cref="InvalidOperationException"/> if there are multiple entities with the given <paramref name="predicate"/>.
/// </para>
/// </summary>
/// <param name="predicate">A condition to filter entities</param>
/// <param name="includeDetails">Set true to include all children of this entity</param>
Expand All @@ -47,10 +51,11 @@ public interface IRepository<TEntity> : IReadOnlyRepository<TEntity>, IBasicRepo
);

/// <summary>
/// Deletes many entities by function.
/// Notice that: All entities fits to given predicate are retrieved and deleted.
/// This may cause major performance problems if there are too many entities with
/// given predicate.
/// Deletes many entities by the given <paramref name="predicate"/>.
/// <para>
/// Please note: This may cause major performance problems if there are too many entities returned for a
/// given predicate and the database provider doesn't have a way to efficiently delete many entities.
/// </para>
/// </summary>
/// <param name="predicate">A condition to filter entities</param>
/// <param name="autoSave">
Expand All @@ -69,4 +74,4 @@ public interface IRepository<TEntity, TKey> : IRepository<TEntity>, IReadOnlyRep
where TEntity : class, IEntity<TKey>
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,7 @@ public override async Task DeleteAsync(Expression<Func<TEntity, bool>> predicate
.Where(predicate)
.ToListAsync(GetCancellationToken(cancellationToken));

foreach (var entity in entities)
{
dbSet.Remove(entity);
}
await DeleteManyAsync(entities, autoSave, cancellationToken);

if (autoSave)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,7 @@ protected virtual async Task ApplyAbpConceptsForDeletedEntityAsync(TEntity entit
{
var entities = (await GetQueryableAsync()).Where(predicate).ToList();

foreach (var entity in entities)
{
await DeleteAsync(entity, autoSave, cancellationToken);
}
await DeleteManyAsync(entities, autoSave, cancellationToken);
}

public override async Task<TEntity> InsertAsync(
Expand Down