/// <summary>
/// Calls the respective insert, update or delete command
/// for each object in the specified collection to save the entity to the database.
/// </summary>
/// <param name="transaction">The transaction to save within.</param>
/// <param name="entities">The entities to save.</param>
/// <param name="batchSize">A value that enables or disables batch processing support, and specifies the number of commands that can be executed in a batch.
/// <para>When the value is 0, the default, the adapter will use the largest batch size the server can handle.</para>
/// <para>When the value is 1 batching is disabled.</para>
/// <para>A value > 1 will send changes to the database using the specified batch size.</para></param>
public virtual void Save(Transaction transaction, ICollection <T> entities, int batchSize = 0)
{
_batchSize = batchSize;
if (_batchSize != 1)
{
InitializeDataAdapter(transaction);
DataTable changes = CreateDataTable(entities);
_dataAdapter.Update(changes);
if (BatchComplete != null)
{
BatchComplete(this, new BatchCompleteEventArgs <T>(entities, changes.Rows));
}
}
else
{
foreach (T entity in entities)
{
Save(transaction, entity);
}
}
}