public IList <Defect> ListDefects() { SqlDbHelper db = new SqlDbHelper(); var table = db.ExecuteDataTable("select * from defects"); return(ModelConvertHelper <Defect> .ConvertToModel(table)); }
public virtual bool Update(T t, string[] columnsToUpdate = null) { string sql; SqlParameter[] parameters; ModelConvertHelper <T> .BuildUpdateStatement(t, TableName, IdName, out sql, out parameters, columnsToUpdate); //TODO retrieve id from db; return(db.ExecuteNonQuery(sql, CommandType.Text, parameters) > 0); }
public IList <T> Find(string whereClause, string orderClause, SqlParameter[] parameters) { var sql = "select * from " + TableName; if (!string.IsNullOrEmpty(whereClause)) { sql += " where " + whereClause; } if (!string.IsNullOrEmpty(orderClause)) { sql += " order by " + orderClause; } var table = db.ExecuteDataTable(sql, CommandType.Text, parameters); return(ModelConvertHelper <T> .ConvertToModel(table)); }
public virtual T Read(object id) { var tableName = typeof(T).Name; string sql = string.Format("select * from {0} where {1} = @id", TableName, _idName); SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@id", id) }; DataTable table = db.ExecuteDataTable(sql, CommandType.Text, parameters); if (table.Rows.Count > 0) { return(ModelConvertHelper <T> .ConvertToModel(table)[0]); } else { return(default(T)); } }
public IList <T> ListAll() { var table = db.ExecuteDataTable("select * from " + TableName); return(ModelConvertHelper <T> .ConvertToModel(table)); }