Beispiel #1
0
        /// <summary>
        ///		Selects multiple records based on filter columns and their values
        /// </summary>
        /// <typeparam name="T">
        ///     Any model object that implements Imodel interface.
        /// </typeparam>
        /// <param name="fieldNames">
        ///		filter on filed names
        /// </param>
        /// <param name="fieldValues">
        ///		filter for field values
        /// </param>
        /// <returns>
        ///		Collection of IModel objects
        ///	</returns>
        public List <T> SelectMultiple <T>(string[] fieldNames, object[] fieldValues) where T : IModel
        {
            SqlCommand    command    = null;
            SqlDataReader dataReader = null;
            List <T>      models     = null;

            command = (SqlCommand)this.CreateSelectCommandForMultipleResults(
                this.modelDataMap, fieldNames, fieldValues);

            command.Connection  = (SqlConnection)this.connection;
            command.Transaction = (SqlTransaction)this.transaction;

            try
            {
                dataReader = command.ExecuteReader();
                DataReaderConverter converter = new DataReaderConverter(this.modelType);
                models = converter.ConvertDataReaderToModels <T>(dataReader);
            }
            finally
            {
                dataReader.Close();
            }

            return(models);
        }
Beispiel #2
0
        /// <summary>
        ///		Generates select command from model and execute that stored procedure
        /// </summary>
        /// <typeparam name="T">
        ///     Any object that implements IModel interface
        /// </typeparam>
        /// <param name="model">
        ///     IModel object with values for stored procedure input parameters
        /// </param>
        /// <returns>
        ///		Imodel object
        /// </returns>
        public List <T> SelectMultipleFromProcedure <T>(IModel model) where T : IModel
        {
            SqlDataReader dataReader = null;
            List <T>      models;

            // creates new as command object using stored procedure
            SqlCommand command = this.commandBuilder.GetSelectMultipleCommand(model);

            command.Transaction = (SqlTransaction)this.transaction;
            command.Connection  = (SqlConnection)this.connection;

            //checking the connection state and making it in Open State
            if (connection.State.ToString() == "Closed")
            {
                connection.Open();
            }

            // executes select stored procedure
            using (dataReader = command.ExecuteReader())
            {
                try
                {
                    DataReaderConverter converter = new DataReaderConverter(this.modelType);
                    models = converter.ConvertDataReaderToModels <T>(dataReader);
                }
                finally
                {
                    dataReader.Close();
                    if (connection.State.ToString() == "Open")
                    {
                        connection.Close();
                    }
                }
            }

            return(models);
        }