Exemplo n.º 1
0
        /// <summary>
        /// Executes a given <see cref="IQuery"/> and returns a collection of the <see cref="DomainObject"/>s returned by the query.
        /// </summary>
        /// <typeparam name="T">The type of <see cref="DomainObjects"/> to be returned from the query.</typeparam>
        /// <param name="query">The query to execute. Must not be <see langword="null"/>.</param>
        /// <returns>
        /// A collection containing the <see cref="DomainObject"/>s returned by the query.
        /// </returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="query"/> is <see langword="null"/>.</exception>
        /// <exception cref="UnexpectedQueryResultException">The objects returned by the <paramref name="query"/> do not match the expected type
        /// <typeparamref name="T"/> or the configured collection type is not assignable to <see cref="ObjectList{T}"/> with the given <typeparamref name="T"/>.</exception>
        /// <exception cref="System.ArgumentException"><paramref name="query"/> does not have a <see cref="Configuration.QueryType"/> of <see cref="Configuration.QueryType.Collection"/>.</exception>
        /// <exception cref="Remotion.Data.DomainObjects.Persistence.Configuration.StorageProviderConfigurationException">
        /// The <see cref="IQuery.StorageProviderDefinition"/> of <paramref name="query"/> could not be found.
        /// </exception>
        /// <exception cref="Remotion.Data.DomainObjects.Persistence.PersistenceException">
        /// The <see cref="Remotion.Data.DomainObjects.Persistence.StorageProvider"/> for the given <see cref="IQuery"/> could not be instantiated.
        /// </exception>
        /// <exception cref="Remotion.Data.DomainObjects.Persistence.StorageProviderException">
        /// An error occurred while executing the query.
        /// </exception>
        public QueryResult <T> GetCollection <T> (IQuery query) where T : DomainObject
        {
            ArgumentUtility.CheckNotNull("query", query);

            if (query.QueryType != QueryType.Collection)
            {
                throw new ArgumentException("A scalar or custom query cannot be used with GetCollection.", "query");
            }

            var resultArray = _objectLoader
                              .GetOrLoadCollectionQueryResult(query)
                              .Select(data => ConvertLoadedDomainObject <T> (data.GetDomainObjectReference())).ToArray();
            var queryResult = new QueryResult <T> (query, resultArray);

            return(_transactionEventSink.RaiseFilterQueryResultEvent(queryResult));
        }