Beispiel #1
0
        /// <summary>
        /// Execute a SQL query and map the results to a collection of a type.
        /// </summary>
        /// <param name="query">SQL string.</param>
        /// <param name="parameters">Dictionary of parameters. Key = parameter name, value = parameter value.</param>
        /// <returns>Collection of type T.</returns>
        protected virtual ICollection <T> Execute <T>(string query, IDictionary <string, object> parameters) where T : new()
        {
            ICollection <T> collection = new List <T>();

            using (IDbConnection connection = CreateConnection())
            {
                using (IDbCommand command = CreateCommand(connection, query, parameters))
                {
                    using (IDataReader reader = command.ExecuteReader())
                    {
                        ColumnMap map = new ColumnMap();

                        collection = map.MapCollection <T>(reader);
                    }
                }
            }
            return(collection);
        }