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

Feature Request: Deletion of entities via specification #363

Closed
thorstenalpers opened this issue Aug 19, 2023 · 5 comments
Closed

Feature Request: Deletion of entities via specification #363

thorstenalpers opened this issue Aug 19, 2023 · 5 comments

Comments

@thorstenalpers
Copy link
Contributor

thorstenalpers commented Aug 19, 2023

Hi, Ardalis Specification is a really great project that I use extensively as Nuget. I have an additional feature request. I have implemented in my own EfRepository, but would like to see in your project. It is about deleting entities per specification.

The existing way is to list entities and then delete them.

 public abstract class RepositoryBase<T> : IReadRepository<T> where T : class
{
...
   public virtual async Task DeleteRangeAsync(ISpecification<T> specification, CancellationToken cancellationToken = default)
    {
        var query = ApplySpecification(specification);
        _dbContext.Set<T>().RemoveRange(query);
        await SaveChangesAsync(cancellationToken);
    }
...
}

I could also create a PR with unittests.

@fiseni
Copy link
Collaborator

fiseni commented Aug 19, 2023

Hi @thorstenalpers

Yea we may add it. Do you want to give it a try?
@ardalis do you have any objections?

@thorstenalpers
Copy link
Contributor Author

thorstenalpers commented Aug 31, 2023

Yeah, I would try it out, I could also create a PR with UnitTests.

@ardalis
Copy link
Owner

ardalis commented Aug 31, 2023

No objections, go for it @thorstenalpers !

@thorstenalpers
Copy link
Contributor Author

thorstenalpers commented Sep 2, 2023

@ardalis I have created a fork and created a branch "feature/delete-range-by-spec" and created a PR in my repository.

PR: #369

I have implemented it for both EF6 and EfCore. EF6 doesn't delete referenced entities automatically, therefore I added some specifications for entities without referenced entities.

If you want some more tests or explanations then feel free to contact me.

@fiseni
Copy link
Collaborator

fiseni commented Sep 8, 2023

Resolved by PR #369

@fiseni fiseni closed this as completed Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants