From reading many other posts it looks like I need to use
context.DbSet<Table>.RemoveRange(…);
context.SaveChanges();
to efficiently remove multiple entities.
Sadly however, in my scenario, this is still taking far too long. In tests, even removing 5 entities with about 10 fields takes about 1 sec per entity. This is far too slow.
What else can I do to improve performance?
Edit
This is what the method looks like that does the work:
public void RemoveClassReportGroupings(IEnumerable<(int clientClassId, int classReportGroupingId)> enumerable)
{
List<Class_ReportGrouping> removeItems = new List<Class_ReportGrouping>();
var dict = _context.ClassReportGroupings.Select(i => i).ToDictionary(i=> (i.ClassId, i.GroupingId));
foreach (var item in enumerable)
{
var removeItem = dict[(item.clientClassId ,item.classReportGroupingId)];
removeItems.Add(removeItem);
}
_context.ClassReportGroupings.RemoveRange(removeItems);
}