public Update ( |
||
dataTable | ||
return | int |
public int Update(DataTable dataTable)
{
long logScopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Update|API> {0}, dataTable", ObjectID);
try
{
if (null == dataTable)
{
throw ADP.UpdateRequiresDataTable(nameof(dataTable));
}
DataTableMapping tableMapping = null;
int index = IndexOfDataSetTable(dataTable.TableName);
if (-1 != index)
{
tableMapping = TableMappings[index];
}
if (null == tableMapping)
{
if (System.Data.MissingMappingAction.Error == MissingMappingAction)
{
throw ADP.MissingTableMappingDestination(dataTable.TableName);
}
tableMapping = new DataTableMapping(DbDataAdapter.DefaultSourceTableName, dataTable.TableName);
}
return UpdateFromDataTable(dataTable, tableMapping);
}
finally
{
DataCommonEventSource.Log.ExitScope(logScopeId);
}
}
/// <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); } } }