public static IEnumerable <T> MyQuery <T>(this ISqlConnectionProvider sqlConnectionProvider, string whereClause = null, string tableName = null, string schemaName = null) { whereClause = whereClause ?? "1 = 1"; var selectClause = GenerateSelectClause <T>(); tableName = SqlTextFunctions.GetTableName(typeof(T), tableName, schemaName); var sqlStatement = $"SELECT {selectClause} FROM {tableName} WHERE {whereClause}"; SqlLogger.LogSqlStatement(sqlStatement); var results = sqlConnectionProvider.Query <T>(sqlStatement).ToList(); return(results); }
public static void Delete <T>(this ISqlConnectionProvider sqlConnectionProvider, T objToDelete, Expression <Func <T, object> > keyProperties = null, string tableName = null, string schemaName = null, bool processColumnNames = true) { tableName = SqlTextFunctions.GetTableName(objToDelete.GetType(), tableName, schemaName); using (var myConnection = sqlConnectionProvider.ToSqlConnection()) { using (var myCommand = new SqlCommand() { Connection = myConnection }) { SqlTextFunctions.UnUnderscoreColumnNames = processColumnNames; BuildOutMyCommand(objToDelete, keyProperties, tableName, myCommand); SqlTextFunctions.UnUnderscoreColumnNames = true; myConnection.Open(); SqlLogger.LogSqlStatement(myCommand.CommandText); myCommand.ExecuteNonQuery(); myConnection.Close(); } } }