/// <summary>
        /// Execute the sql script and returns the list
        /// </summary>
        /// <param name="sqlScript"></param>
        /// <param name="entityMappingDefinition"></param>
        /// <returns></returns>
        public object ExecuteReaderAndReturnList(string sqlScript, EntityMappingDefinition entityMappingDefinition)
        {
            _connectionManager.Open();

            var listType = typeof(List<>);
            var constructedListType = listType.MakeGenericType(entityMappingDefinition.EntityType);
            IList result = (IList)Activator.CreateInstance(constructedListType);

            var command = new SqlCommand();
            command.CommandText = sqlScript;
            command.CommandType = CommandType.Text;
            command.Connection = _connectionManager.Connection;

            var reader = command.ExecuteReader();
            if (reader.HasRows)
            {
                var columnNames = GetColumnNames(reader);
                while (reader.Read())
                {
                    var instance = _recordReader.MapToEntity(reader, entityMappingDefinition, columnNames);

                    result.Add(instance);
                }
            }

            reader.Close();
            _connectionManager.Close();

            return result;
        }
Exemple #2
0
 public BaseMapping()
 {
     _entityMappingDefinition = new EntityMappingDefinition(typeof(TSource));
 }