public static string GetInsertStatement(System.Type type) { Dictionary <string, string> columnNames = DatabaseUtilities.getColumns(type); columnNames.Remove(DatabaseUtilities.GetKeyColumn(type).Key); return(string.Format("INSERT INTO {0}({1}) VALUES({2})", DatabaseUtilities.GetTableName(type), string.Join(",", columnNames.Keys), string.Join(",", columnNames.Values))); }
public static string GetUpdateStatement(System.Type type) { Dictionary <string, string> columnNames = DatabaseUtilities.getColumns(type); columnNames.Remove(DatabaseUtilities.GetKeyColumn(type).Key); return(string.Format("UPDATE {0} SET {1}", DatabaseUtilities.GetTableName(type), string.Join(",", from x in columnNames select string.Format("{0} = {1}", x.Key, x.Value)))); }
public int Delete <T>(int id) { System.Type type = typeof(T); DbCommand command = this.GetSqlStringCommand("DELETE FROM " + DatabaseUtilities.GetTableName(type)); System.Collections.Generic.KeyValuePair <string, string> key = DatabaseUtilities.GetKeyColumn(type); string prefix = (command is System.Data.SqlClient.SqlCommand) ? "@" : ":"; string whereClause = string.Format(" WHERE {0} = {1}{2}", key.Key, prefix, key.Value); DbCommand expr_5C = command; expr_5C.CommandText += whereClause; this.AddInParameter(command, prefix + key.Value, System.Data.DbType.Int32, id); return(this.ExecuteNonQueryCommand(command)); }
public static string GetSelectStatement(System.Type type) { Dictionary <string, string> columnNames = DatabaseUtilities.getColumns(type); return(string.Format("SELECT {0} FROM {1}", DatabaseUtilities.buildSelectColumns(columnNames), DatabaseUtilities.GetTableName(type))); }