/// <summary> /// Loads an instane of T using the connection passed in the constructor /// </summary> /// <param name="commandType">SQL command type, normally this is stored procedure</param> /// <param name="commandText">Command text, normally this is the stored procedure name</param> /// <param name="commandBehavior">SQLDataReader CommandBeharior</param> /// <param name="commandTimeOut">Time out value for this request</param> /// <param name="parameters">Param array of SQL Parameter objects. For inbound parameters you must set the value of the parameter</param> /// <returns>Instance of T</returns> public T LoadOne(CommandType commandType, String commandText, CommandBehavior commandBehavior, Int32 commandTimeOut, params SqlParameter[] parameters) { _affectedRows = 0; using(SqlDataReader reader = _dataAccess.GetDataReader(commandType, commandText, commandBehavior, parameters)) { var builder = new ReflectionBuilder<T>(); while(reader.Read()) { _affectedRows += 1; _returnCode = DatabaseReturnCode.Successful; return builder.Build(reader); } } _returnCode = DatabaseReturnCode.RecordNotFound; return default(T); }
/// <summary> /// Loads an ObservableCollection using the connection passed in the constructor /// </summary> /// <param name="commandType">SQL command type, normally this is stored procedure</param> /// <param name="commandText">Command text, normally this is the stored procedure name</param> /// <param name="commandBehavior">SQLDataReader CommandBeharior</param> /// <param name="commandTimeOut">Time out value for this request</param> /// <param name="parameters">Param array of SQL Parameter objects. For inbound parameters you must set the value of the parameter</param> /// <returns>ObservableCollection</returns> public ObservableCollection<T> LoadObservableCollection(CommandType commandType, String commandText, CommandBehavior commandBehavior, Int32 commandTimeOut, params SqlParameter[] parameters) { var result = new ObservableCollection<T>(); using(SqlDataReader reader = _dataAccess.GetDataReader(commandType, commandText, commandBehavior, parameters)) { var builder = new ReflectionBuilder<T>(); while(reader.Read()) { result.Add(builder.Build(reader)); } } _affectedRows = result.Count; _returnCode = DatabaseReturnCode.Successful; return result; }
/// <summary> /// Initializes a new instance of the <see cref="DataAccessException"/> class. /// </summary> /// <param name="returnCode">The return code.</param> /// <param name="message">The message.</param> /// <param name="innerException">The inner exception.</param> public DataAccessException(DatabaseReturnCode returnCode, String message, Exception innerException) : base(message, innerException) { this.ReturnCode = returnCode; }
/// <summary> /// Initializes a new instance of the <see cref="DataAccessException"/> class. /// </summary> /// <param name="returnCode">The return code.</param> /// <param name="source">The source.</param> /// <param name="message">The message.</param> /// <param name="innerException">The inner exception.</param> public DataAccessException(DatabaseReturnCode returnCode, String source, String message, Exception innerException) : base(message, innerException) { base.Data.Add("Source", source); this.ReturnCode = returnCode; }