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