/// <summary> /// Executes a given <see cref="IQuery"/> and uses a delegate to convert the results into arbitrary objects. The result sequence may be lazy and /// streamed, i.e., the query results may be gathered while the sequence is enumerated. The underlying <see cref="StorageProvider" /> may keep /// resources (such as a database connection) open while the sequence is enumerated, see remarks. /// </summary> /// <typeparam name="T">The type of values to be returned by the query.</typeparam> /// <param name="query">The query to execute. Must not be <see langword="null"/>.</param> /// <param name="rowReader">A delegate that is used to convert the query result, represented as an <see cref="IQueryResultRow"/>, /// into the query result type, <typeparamref name="T"/>.</param> /// <returns>A collection containing the objects produced by the <paramref name="rowReader"/>-delegate.</returns> /// <remarks> /// The underlying <see cref="StorageProvider" /> may implement this method in such a way that the query is only executed when the returned /// <see cref="IEnumerable{T}"/> is enumerated. Resources, such as a database connection or transaction, may be kept open during that /// enumeration until the <see cref="IEnumerator{T}"/> is disposed. Use "<see cref="Enumerable"/>.ToArray()" or iterate immediately if you require /// those resources to be freed as quickly as possible. /// </remarks> public IEnumerable <T> GetCustom <T> (IQuery query, Func <IQueryResultRow, T> rowReader) { ArgumentUtility.CheckNotNull("query", query); ArgumentUtility.CheckNotNull("rowReader", rowReader); if (query.QueryType != QueryType.Custom) { throw new ArgumentException("A collection or scalar query cannot be used with GetCustom.", "query"); } if (query.EagerFetchQueries.Count > 0) { throw new ArgumentException("A custom query cannot have eager fetch queries defined.", "query"); } var queryResult = _persistenceStrategy.ExecuteCustomQuery(query).Select(rowReader); return(_transactionEventSink.RaiseFilterCustomQueryResultEvent(query, queryResult)); }