Entity Framework bulk insert unreal slow
<p>I am using EF 6. I am trying to insert around 200.000 entities while saving changes to database after each 100 entities.</p>

<p>The issue is it took 11 hours to save 50.000 entities, and it is still running behind. I am running this with WebJobs, and job is published on the same azure webapp as main website. Is the issue because of that and WebJob don't have enough resources, or saving after 100 entities, or the approach?</p>

<p><strong>Method</strong></p>

<pre><code>public void SaveLeadsForBuyer(ISenderModel model)
{
    var rowCounter = 0;

    foreach (var deliveryRecord in model.Customers.Select(customerModel =&gt; new DeliveryRecord()
    {
        BuyerId = model.Buyer.Id,
        AspNetUserId = customerModel.Id,
        DeliveryType = model.Buyer.DeliveryType,
        CreatedOn = DateTime.UtcNow
    }))
    {
        ++rowCounter;

        _unit.Repository&lt;DeliveryRecord&gt;().Insert(deliveryRecord);

        _unit.SaveChangesPartially(rowCounter, 100);
    }

    _unit.SaveChanges();
}
</code></pre>

<p><strong>Helper</strong></p>

<pre><code>public static class UnitOfWorkHelper
{
    /// &lt;summary&gt;
    /// Helper method triggers SaveChanges() after amount of rows provided through "amount" parameter in method
    /// &lt;/summary&gt;
    /// &lt;param name="unit"&gt;UnitOfWork object&lt;/param&gt;
    /// &lt;param name="count"&gt;Current amount of rows&lt;/param&gt;
    /// &lt;param name="saveCount"&gt;Amount when to save changes to database&lt;/param&gt;
    public static void SaveChangesPartially(this IUnitOfWorkAsync unit, int count, int saveCount)
    {
        if (count % saveCount == 0)
        {
            unit.SaveChanges();
        }
    }
}
</code></pre>