示例#1
0
        /// <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);
        }
示例#2
0
        /// <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;
        }