/// <summary> /// Gets the one. /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public Category GetOne(int id) { string sqlStatement = "select * from Categories where CategoryID = @CategoryID"; var item = new Category(); using (var conn = this.CreateGlimpseDbConnection()) using (var command = new GlimpseDbCommand(new SqlCommand())) { command.Connection = conn; command.CommandType = CommandType.Text; command.CommandTimeout = 180; command.CommandText = sqlStatement; command.Parameters.Add(new SqlParameter("CategoryID", id)); if (conn.State != ConnectionState.Open) { conn.Open(); } using (IDataReader reader = command.ExecuteReader()) { if (reader.Read()) { item.CategoryID = int.Parse(reader["CategoryID"].ToString()); item.CategoryName = reader["CategoryName"].ToString(); item.Description = reader["Description"].ToString(); } } } return(item); }
/// <summary> /// Unwraps the given command and returns the inner command. /// </summary> /// <param name="command">The outer command.</param> /// <returns>The inner command.</returns> public override IDbCommand GetInnerCommand(IDbCommand command) { if (command == null) { throw new ArgumentNullException("command"); } GlimpseDbCommand profiledCommand = (GlimpseDbCommand)command; return(profiledCommand.InnerCommand); }
public IDbCommand GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes) { var innerCommand = _innerDriver.GenerateCommand(type, sqlString, parameterTypes); if (innerCommand is GlimpseDbCommand) { return(innerCommand); } var command = new GlimpseDbCommand(innerCommand as DbCommand); return(command); }
/// <summary> /// Gets the categories. /// </summary> /// <returns></returns> public List <Category> GetCategories() { var categories = new List <Category>(); string sqlStatement = "select * from Categories order by CategoryID desc"; using (var conn = this.CreateGlimpseDbConnection()) using (var command = new GlimpseDbCommand(new SqlCommand())) { command.Connection = conn; command.CommandType = CommandType.Text; command.CommandTimeout = 180; command.CommandText = sqlStatement; if (conn.State != ConnectionState.Open) { conn.Open(); } using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var item = new Category { CategoryID = int.Parse(reader["CategoryID"].ToString()), CategoryName = reader["CategoryName"].ToString(), Description = reader["Description"].ToString() }; categories.Add(item); } } } return(categories); }