Batch save with progress reporting
var count = 0;
var lastPercentage = 0d;

var nextBatch = new Func&lt;bool&gt;(() =&gt; ++count % batchSize == 0);



It was a clever usage of context capture but I think it ended up playing against you.

Your method has way too much responsibility. You should had at least another method to resolve the batching problem. Because you mixed the two things(batch + db stuff) you ended up by having this:

var enumerator = items.GetEnumerator();
while (enumerator.MoveNext())
{
    //...
    do{
       //...
    } while (!nextBatch() &amp;&amp; enumerator.MoveNext());
}


And the first thing that I thought about was: "Why the hell is he advancing the enumerator twice? Why couldn't he use foreach instead?" And than I realized, without even parsing the code too much: "Ah it must be because of the batching stuff...". 

It doesn't really matter if I got that right or not, I had to spend time to think about it, asking this kind questions is very useful actually. I would strongly suggest you next time you see yourself using enumerator.MoveNextto ask the same thing. Why aren't you using foreach?

Anyway, as I said you should separate those two concerns. A batch implementation would become like this:

public IEnumerable&lt;IEnumerable&lt;int&gt;&gt; Batch(int total, int batchSize){
    for(int i = 0; i &lt; total; i += batchSize){
        var currentBatchSize = Math.Min(batchSize, total - i);
        yield return Enumerable.Range(i * batchSize, currentBatchSize);
    }
}


A similar thing could be said about reportProgress. You ended up by creating abstraction over a simple calculation that is to calculate the report progress(with a simple mathematical formula). It didn't really contribute in any positive way to the readability/maintainability of your code.

Putting that all into a new implementation would look like this:

public static IEnumerable&lt;IEnumerable&lt;int&gt;&gt; GetBatches(int total, int batchSize){
    for(int i = 0; i &lt; total; i += batchSize){
        var currentBatchSize = Math.Min(batchSize, total - i);
        yield return Enumerable.Range(i, currentBatchSize);
    }
}

public static void BatchSave&lt;T, TContext&gt;(
    this IList&lt;T&gt; items,
    int batchSize, 
    Func&lt;TContext&gt; createContext,
    IProgress&lt;double&gt; progress
)
    where T : class
    where TContext : DbContext
{
    var batches = GetBatches(items.Count, batchSize).ToList();
    int currentBatch = 0;
    foreach(var batch in batches){
        using (var context = createContext())
        {
            context.Configuration.AutoDetectChangesEnabled = false;
            context.Configuration.ValidateOnSaveEnabled = false;

            foreach(var i in batch){
                Console.WriteLine("Add " + items[i]);
            }
            //context.SaveChanges();
            progress.Report(++currentBatch * 100.0 / batches.Count);
            Console.WriteLine("Save batch = " + currentBatch);
        }
    }

    progress.Report(100);
}


This alternative might yet lack something. For example, if you are really a neat freak, maybe you would try to change the return result of GetBatches in someway to be more useful. One thing that could be useful is to know which batch is the current batch. Should the return be IEnumerable&lt;IEnumerable&lt;Tuple&lt;int, int&gt;&gt;&gt;(where tuple can be another classes with two integers if you want...). Would it be more useful to turn it to GetBatches&lt;T&gt;? with IEnumerable&lt;IEnumerable&lt;T&gt;&gt; return? Well I will leave that for you to decide, at least I am providing the foundations for it.

One another thing that might be worth pointing is that there isn't really a reason to createContext() multiple times, you can create it just one time, and just call SaveChanges per each batch. Or maybe there is an efficiency reason, that I am not aware of... but you have to prove it by measuring.