当前位置: 首页>>代码示例>>C#>>正文


C# AdoAdapter.InTransaction方法代码示例

本文整理汇总了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;
        }
开发者ID:rafsawicki,项目名称:Simple.Data.Firebird,代码行数:66,代码来源:FbBulkInserter.cs


注:本文中的Simple.Data.Ado.AdoAdapter.InTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。