本文整理匯總了C#中Simple.Data.Ado.AdoAdapter.InTransaction方法的典型用法代碼示例。如果您正苦於以下問題:C# AdoAdapter.InTransaction方法的具體用法?C# AdoAdapter.InTransaction怎麽用?C# AdoAdapter.InTransaction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Simple.Data.Ado.AdoAdapter
的用法示例。
在下文中一共展示了AdoAdapter.InTransaction方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Insert
public IEnumerable<IDictionary<string, object>> Insert(AdoAdapter adapter, string tableName, IEnumerable<IDictionary<string, object>> dataList, IDbTransaction transaction, Func<IDictionary<string, object>, Exception, bool> onError,
bool resultRequired)
{
//ToDo: support onError collection
List<IDictionary<string, object>> result = new List<IDictionary<string, object>>();
if (transaction == null)
{
adapter.InTransaction(currentTransaction =>
{
result = (List<IDictionary<string, object>>) Insert(adapter, tableName, dataList, currentTransaction, onError, resultRequired);
});
return result;
}
var table = adapter.GetSchema().FindTable(tableName);
var tableColumns = table.Columns.Select(c => (FbColumn)c).ToArray();
var nameToFbColumns = tableColumns.ToDictionary(c => c.HomogenizedName, c => c);
var insertContext = CreateInsertSqlContext(table.QualifiedName, tableColumns);
var queryBuilder = new FbBulkInsertQueryBuilder(resultRequired, insertContext.ReturnsExecuteBlockSql);
var insertSqlProvider = new FbBulkInsertSqlProvider();
var currentColumns = new List<InsertColumn>();
foreach (var data in dataList)
{
var insertData = data.Where(p => nameToFbColumns.ContainsKey(p.Key.Homogenize())).Select(kv => new InsertColumn
{
Value = kv.Value,
Column = nameToFbColumns[kv.Key.Homogenize()]
}).ToArray();
ExecuteBlockInsertSql insertSql = insertSqlProvider.GetInsertSql(insertContext, insertData, resultRequired);
if (insertContext.SkipCommandParameters && !CanInsertInExecuteBlock(insertSql.InsertSql, queryBuilder))
{
insertSql = insertSqlProvider.GetInsertSql(insertContext, insertData, resultRequired, skipCommandParameters: false);
}
if (queryBuilder.CanAddQuery(insertSql))
{
queryBuilder.AddQuery(insertSql);
if (!insertContext.SkipCommandParameters) currentColumns.AddRange(insertData);
}
else
{
var subResult = CreateAndExecuteInsertCommand(transaction, currentColumns, queryBuilder.GetSql(), resultRequired);
if (resultRequired) result.AddRange(subResult);
currentColumns.Clear();
queryBuilder = new FbBulkInsertQueryBuilder(resultRequired, insertContext.ReturnsExecuteBlockSql);
queryBuilder.AddQuery(insertSql);
if (!insertContext.SkipCommandParameters) currentColumns.AddRange(insertData);
}
}
if (queryBuilder.QueryCount > 0)
{
var subResult = CreateAndExecuteInsertCommand(transaction, currentColumns, queryBuilder.GetSql(), resultRequired);
if (resultRequired) result.AddRange(subResult);
}
return result;
}