Base solution for your next web application
Open Closed

Quick way to bulk/mass delete a table #3473


User avatar
0
20summers created

I have a table where I store the current sales values that I import from an excel file.

Is there a quicker way to do this than each item being deleted?

var query = _crmOpportunityRepository
                    .GetAll();

                foreach (var item in query)
                {
                    await _crmOpportunityRepository.DeleteAsync(item.Id);
                }

3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    AspNet Zero and ABP does not have anything for built in bulk operations. If your data is so big, then you can use raw sql, otherwise you can check bulk operation libraries for entity framework.

    Thanks.

  • User Avatar
    0
    20summers created

    Hi,

    Would I load the Nuget for this into the Application, Core, or EntitiyFrameworkCore Projects?

  • User Avatar
    0
    alper created
    Support Team

    Hi, You can execute TRUNCATE TABLE tableName query for cleanup table. Or if there's performance bottleneck while deleting records you can use Dapper. ABP has integration with dapper. <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Nuget-Packages#abpdapper">https://aspnetboilerplate.com/Pages/Doc ... #abpdapper</a>