本文整理汇总了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;
}