2

How can I delete a list of entities, without using a loop, in ASP.NET Boilerplate MVC?

Currently, I use:

foreach (var data in sampleDataList)
{
    _iRepositorySampleData.Delete(data);
}

But I don't want to use a loop to delete multiple entities.

aaron
  • 39,695
  • 6
  • 46
  • 102
taymyinl
  • 295
  • 4
  • 15
  • 2
    What is wrong with what you currently doing? Even `RemoveRange()` - or indeed any method that would delete multiple items - is going to have to use a loop internally) –  Mar 06 '18 at 01:58
  • wrong with my team leader haha I told him like that. and I also want to know if there is some function like RemoveRange in Asp.net Boilerplate. – taymyinl Mar 06 '18 at 02:39

1 Answers1

5

ASP.NET Boilerplate's IRepository does not provide RemoveRange out-of-the-box as:

ASP.NET Boilerplate is designed to be independent from a particular ORM (Object/Relational Mapping) framework or another technique to access a database.1

Feature requests in the backlog:

At the moment, there is not much going for it as it's already possible, so there is little value added.

EF Core

// using Abp.EntityFrameworkCore.Repositories;

repository.GetDbContext().RemoveRange(sampleDataList);

EF6

// using Abp.EntityFramework.Repositories;

var type = sampleDataList.GetType().GetGenericArguments().Single();
repository.GetDbContext().Set(type).RemoveRange(sampleDataList);
aaron
  • 39,695
  • 6
  • 46
  • 102