Try this:
public static class DataExtensions
{
public static IEnumerable<IEnumerable<DataRow>> Partition(this DataTable dataTable, int partitionSize)
{
var numRows = Math.Ceiling((double)dataTable.Rows.Count);
for(var i = 0; i < numRows / partitionSize; i++)
{
yield return Partition(dataTable, i * partitionSize, i * partitionSize + partitionSize);
}
}
private static IEnumerable<DataRow> Partition(DataTable dataTable, int index, int endIndex)
{
for(var i = index; i < endIndex && i < dataTable.Rows.Count; i++)
{
yield return dataTable.Rows[i];
}
}
}
var partitions = dataTable.Partition(100);
Doing:
dataTable.Skip(0).Take(100);
dataTable.Skip(100).Take(100);
dataTable.Skip(200).Take(100);
dataTable.Skip(300).Take(100);
Will iterate 0 times, and take 100 on the first execution. Then iterate through 100 rows, take 100, then iterate 200 rows, then take 100, etc.
The above will do a lazy fetch and only hit each row once