protected override TablePair Write(IDbConnection connection, DataTable table, string tempTableName = null) { var bulkCopy = new SqlBulkCopy(connection.AsSqlConnection()); if (string.IsNullOrWhiteSpace(tempTableName)) { tempTableName = CreateTempSchema(connection, table).TableName; } Write(bulkCopy, table, tempTableName); return(new TablePair(table.TableName, tempTableName)); }
protected override IDbCommand CreateDbCommand( IDbConnection connection, string query, IDictionary <string, object> parameters = null, CommandType commandType = CommandType.Text) { var sqlCommand = new SqlCommand(query, connection.AsSqlConnection()) { CommandType = commandType, CommandTimeout = 0 }; AddParameters(sqlCommand, parameters); return(sqlCommand); }
/// <summary> /// Attempts to use the OpenAsync method of the connection if supported, otherwise the synchronous Open method is invoked. /// </summary> /// <param name="connection">The connection.</param> /// <param name="cancellationToken"></param> /// <returns>An awaitable task.</returns> public static async Task OpenAsync([NotNull] this IDbConnection connection, CancellationToken cancellationToken = default) { Contract.Requires(connection != null); var sqlConnection = connection.AsSqlConnection(); if (sqlConnection != null) { await sqlConnection.OpenAsync(cancellationToken); return; } connection.Open(); }
protected override IList <TablePair> Write(IDbConnection connection, DataSet data, IEnumerable <TablePair> tempTableMap = null) { var result = new List <TablePair>(); var bulkCopy = new SqlBulkCopy(connection.AsSqlConnection()); var tempTables = tempTableMap?.ToDictionary(x => x.LiveTable, x => x.TempTable); string tempTableName = null; foreach (DataTable table in data.Tables) { if (!(tempTables?.TryGetValue(table.TableName, out tempTableName) ?? false) || string.IsNullOrWhiteSpace(tempTableName)) { tempTableName = CreateTempSchema(connection, table).TableName; } Write(bulkCopy, table, tempTableName); result.Add(new TablePair(table.TableName, tempTableName)); } return(result); }