當前位置: 首頁>>代碼示例>>C#>>正文


C# AdoAdapter.CreateConnection方法代碼示例

本文整理匯總了C#中Simple.Data.Ado.AdoAdapter.CreateConnection方法的典型用法代碼示例。如果您正苦於以下問題:C# AdoAdapter.CreateConnection方法的具體用法?C# AdoAdapter.CreateConnection怎麽用?C# AdoAdapter.CreateConnection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Simple.Data.Ado.AdoAdapter的用法示例。


在下文中一共展示了AdoAdapter.CreateConnection方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Insert

        public IDictionary<string, object> Insert(AdoAdapter adapter, string tableName, IDictionary<string, object> data, IDbTransaction transaction, bool returnRequired)
        {
            var s = DatabaseSchema.Get(adapter.ConnectionProvider, new ProviderHelper());
            var table = s.FindTable(tableName);
            
            var tuples = InitializeInsertion(table);
            foreach (var d in data)
                tuples[d.Key.Homogenize()].InsertedValue = d.Value;

            Func<IDbCommand> command =
                () =>
                    {
                        var c = transaction != null
                                    ? transaction.Connection.CreateCommand()
                                    : adapter.CreateConnection().CreateCommand();
                        return c;
                    };

            IDbCommand cmd;
            using (cmd = ConstructCommand(tuples, table.QualifiedName, command))
            {
                cmd.WriteTrace();
                cmd.Connection.TryOpen();
                cmd.ExecuteNonQuery();
                var returnData = new DbDictionary();
                foreach (var it in tuples.Values)
                    returnData.Add(it.SimpleDataColumn, NormalizeReturningValue((IDbDataParameter)cmd.Parameters[it.ReturningParameterName]));
                data = returnData;
            }

            return data;
        }
開發者ID:JorgeGamba,項目名稱:Simple.Data.Oracle,代碼行數:32,代碼來源:OracleInserter.cs

示例2: InsertRowsWithSeparateStatements

        private static IEnumerable<IDictionary<string, object>> InsertRowsWithSeparateStatements(AdoAdapter adapter, IEnumerable<IDictionary<string, object>> data,
                                                                    IDbTransaction transaction, Table table, List<Column> columns,
                                                                    string insertSql, string selectSql)
        {
            if (transaction != null)
            {
                var insertCommand = new CommandHelper(adapter.SchemaProvider).Create(transaction.Connection, insertSql);
                var selectCommand = transaction.Connection.CreateCommand();
                selectCommand.CommandText = selectSql;
                insertCommand.Transaction = transaction;
                selectCommand.Transaction = transaction;
                return data.Select(row => InsertRow(row, columns, table, insertCommand, selectCommand)).ToList();
            }

            using (var connection = adapter.CreateConnection())
            {
                using (var insertCommand = new CommandHelper(adapter.SchemaProvider).Create(connection, insertSql))
                using (var selectCommand = connection.CreateCommand())
                {
                    selectCommand.CommandText = selectSql;
                    connection.Open();
                    return data.Select(row => InsertRow(row, columns, table, insertCommand, selectCommand)).ToList();
                }
            }
        }
開發者ID:darrencauthon,項目名稱:Simple.Data,代碼行數:25,代碼來源:BulkInserter.cs

示例3: InsertRowsWithoutFetchBack

 private static void InsertRowsWithoutFetchBack(AdoAdapter adapter, IEnumerable<IDictionary<string, object>> data, Table table, List<Column> columns,
                                                string insertSql)
 {
     using (var connection = adapter.CreateConnection())
     {
         using (var insertCommand = new CommandHelper(adapter.SchemaProvider).Create(connection, insertSql))
         {
             connection.Open();
             foreach (var row in data)
             {
                 InsertRow(row, columns, table, insertCommand);
             }
         }
     }
 }
開發者ID:darrencauthon,項目名稱:Simple.Data,代碼行數:15,代碼來源:BulkInserter.cs

示例4: Update

        public int Update(AdoAdapter adapter, string tableName, IList<IDictionary<string, object>> data, IEnumerable<string> criteriaFieldNames, IDbTransaction transaction)
        {
            int count = 0;
            if (data == null || !data.Any()) 
                return count;

            var criteriaFieldNameList = criteriaFieldNames.ToList();
            if (criteriaFieldNameList.Count == 0) throw new NotSupportedException("Adapter does not support key-based update for this object.");

            if (!AllRowsHaveSameKeys(data)) throw new SimpleDataException("Records have different structures. Bulk updates are only valid on consistent records.");
            var table = adapter.GetSchema().FindTable(tableName);

            var exampleRow = new Dictionary<string, object>(data.First(), HomogenizedEqualityComparer.DefaultInstance);

            var commandBuilder = new UpdateHelper(adapter.GetSchema()).GetUpdateCommand(tableName, exampleRow,
                                                                    ExpressionHelper.CriteriaDictionaryToExpression(
                                                                        tableName, GetCriteria(criteriaFieldNameList, exampleRow)));

            var connection = adapter.CreateConnection();
            using (connection.MaybeDisposable())
            using (var command = commandBuilder.GetRepeatableCommand(connection))
            {
                if (transaction != null)
                {
                    command.Transaction = transaction;
                }
                connection.OpenIfClosed();
                var propertyToParameterMap = CreatePropertyToParameterMap(data, table, command);

                foreach (var row in data)
                {
                    foreach (var kvp in row)
                    {
                        if (propertyToParameterMap.ContainsKey(kvp.Key))
                        {
                            propertyToParameterMap[kvp.Key].Value = kvp.Value ?? DBNull.Value;
                        }
                    }
                    count += command.ExecuteNonQuery();
                }
            }

            return count;
        }
開發者ID:robertwilczynski,項目名稱:Simple.Data,代碼行數:44,代碼來源:BulkUpdater.cs

示例5: ExecuteSingletonQuery

        internal IDictionary<string, object> ExecuteSingletonQuery(AdoAdapter adapter, string sql, IEnumerable<Column> columns, IEnumerable<Object> values, IDbTransaction transaction)
        {
            if (transaction != null)
            {
                var command = new CommandHelper(adapter).CreateInsert(transaction.Connection, sql, columns, values.ToArray());
                command.Transaction = transaction;
                return TryExecuteSingletonQuery(command);
            }

            var connection = adapter.CreateConnection();
            using (connection.MaybeDisposable())
            {
                using (var command = new CommandHelper(adapter).CreateInsert(connection, sql, columns, values.ToArray()))
                {
                    connection.OpenIfClosed();
                    return TryExecuteSingletonQuery(command);
                }
            }
        }
開發者ID:crmmvio,項目名稱:Simple.Data,代碼行數:19,代碼來源:SqlCustomInserter.cs

示例6: InsertRowsWithCompoundStatement

        private static IEnumerable<IDictionary<string, object>> InsertRowsWithCompoundStatement(AdoAdapter adapter, IEnumerable<IDictionary<string, object>> data,
                                                                   IDbTransaction transaction, Table table, List<Column> columns,
                                                                   string selectSql, string insertSql)
        {
            insertSql += "; " + selectSql;
            if (transaction != null)
            {
                var command = new CommandHelper(adapter.SchemaProvider).Create(transaction.Connection, insertSql);
                command.Transaction = transaction;
                return data.Select(row => InsertRowAndSelect(row, columns, table, command)).ToList();
            }

            using (var connection = adapter.CreateConnection())
            {
                using (var command = new CommandHelper(adapter.SchemaProvider).Create(connection, insertSql))
                {
                    connection.Open();
                    return data.Select(row => InsertRowAndSelect(row, columns, table, command)).ToList();
                }
            }
        }
開發者ID:darrencauthon,項目名稱:Simple.Data,代碼行數:21,代碼來源:BulkInserter.cs


注:本文中的Simple.Data.Ado.AdoAdapter.CreateConnection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。