title: C# Efficiently delete 50000 records in batches using SQLBulkCopy or equivalent library
body: <p>I'm using this library to perform bulk delete in batches like following:</p>
  
  <pre><code>  while (castedEndedItems.Any())
    {
      var subList = castedEndedItems.Take(4000).ToList();
      DBRetry.Do(() =&gt; EFBatchOperation.For(ctx, ctx.SearchedUserItems).Where(r =&gt; subList.Any(a =&gt; a == r.ItemID)).Delete(), TimeSpan.FromSeconds(2));
      castedEndedItems.RemoveRange(0, subList.Count);
      Console.WriteLine("Completed a batch of ended items");
    }
  </code></pre>
  
  <p>As you can see guys I take a batch of 4000 items to delete at once and I pass them as argument to the query...</p>
  
  <p>I'm using this library to perform bulk delete:</p>
  
  <pre><code>https://github.com/MikaelEliasson/EntityFramework.Utilities
  </code></pre>
  
  <p>However the performance like this is absolutely terrible... I tested the application couple of times and to delete the 80000 records for example it takes literally 40 minutes!? </p>
  
  <p>I should note that that parameter by which I'm deleting (ItemID) is of varchar(400) type and it's indexed for performance reasons....</p>
  
  <p>Is there any other library that I could possibly use or tweak this query to make it work faster, because currently the performance is absolutely terrible.. :/</p>