private void CreateStagingTable(EntityTable table) { EntitySQLBuilder <TBase> sql = new EntitySQLBuilder <TBase>(mapping); sql.CreateStagingTable(table); using SqlCommand cmd = _connection.CreateCommand(); cmd.CommandText = sql.ToString(); cmd.CommandType = CommandType.Text; cmd.Transaction = _transaction; Logger.Debug($"Creating staging table {table.StagingTable.Name}"); Logger.Debug($"Executing SQL: {sql.ToString()}"); cmd.ExecuteNonQuery(); }
private string GetReadString() { EntitySQLBuilder <TBase> sqlBuilder = new EntitySQLBuilder <TBase>(GetMapping()); sqlBuilder.BuildSelectStatement(); string sql = sqlBuilder.ToString(); Logger.Info(MethodBase.GetCurrentMethod(), "Generated SQL: " + sql); return(sql); }
private string GetUpdateString() { EntitySQLBuilder <TBase> sqlBuilder = new EntitySQLBuilder <TBase>(GetMapping()); sqlBuilder.AppendLine(); sqlBuilder.BuildUpdateStatement(); // For update statements return the number of rows affected sqlBuilder.SelectRowCount(); string sql = sqlBuilder.ToString(); Logger.Info(MethodBase.GetCurrentMethod(), "Generated SQL: " + sql); return(sql); }
private void InsertFromStagingTable(EntityTable table) { EntitySQLBuilder <TBase> sql = new EntitySQLBuilder <TBase>(mapping); string primaryKeyColumnName = table.GetPrimaryKeyColumn().Name; sql.BuildInsertFromStagingToMainWithOutputIds(table); using SqlCommand cmd = _connection.CreateCommand(); cmd.CommandText = sql.ToString(); cmd.CommandType = CommandType.Text; cmd.Transaction = _transaction; int totalPrimaryKeys = ReadPrimaryKeys(cmd, table, primaryKeyColumnName); Logger.Debug($"{(totalPrimaryKeys == 0 ? "No" : totalPrimaryKeys.ToString())} {table.Name} were inserted"); }