/// <summary>
        /// Asynchronously creates a <see cref="RecordSetReader"/> instance capable to read <paramref name="provider"/>
        /// execution results and bound to the specified <paramref name="context"/>.
        /// </summary>
        /// <param name="context">The <see cref="EnumerationContext"/> instance associated with the query execution.</param>
        /// <param name="provider">The <see cref="ExecutableProvider"/> to be processed.</param>
        /// <param name="token">The <see cref="CancellationToken"/> allowing to cancel query execution if necessary.</param>
        /// <returns><see cref="RecordSetReader"/> instance ready for enumeration.
        /// This means query is already executed but no records have been read yet.</returns>
        public static async ValueTask <RecordSetReader> CreateAsync(
            EnumerationContext context, ExecutableProvider provider, CancellationToken token)
        {
            var recordSet = new RecordSetReader(context, provider, token);
            await recordSet.Prepare(true).ConfigureAwait(false);

            return(recordSet);
        }
        /// <summary>
        /// Creates a <see cref="RecordSetReader"/> instance capable to read <paramref name="provider"/>
        /// execution results and bound to the specified <paramref name="context"/>.
        /// </summary>
        /// <param name="context">The <see cref="EnumerationContext"/> instance associated with the query execution.</param>
        /// <param name="provider">The <see cref="ExecutableProvider"/> to be processed.</param>
        /// <returns><see cref="RecordSetReader"/> instance ready for enumeration.
        /// This means query is already executed but no records have been read yet.</returns>
        public static RecordSetReader Create(EnumerationContext context, ExecutableProvider provider)
        {
            var recordSet = new RecordSetReader(context, provider);
            var task      = recordSet.Prepare(false);

            task.GetAwaiter().GetResult(); // Ensure exception, if any, is being thrown
            return(recordSet);
        }
示例#3
0
        /// <summary>
        /// Converts the <see cref="RecordSetReader"/> items to <see cref="Entity"/> instances.
        /// </summary>
        /// <param name="source">The <see cref="RecordSetReader"/> to process.</param>
        /// <param name="primaryKeyIndex">Index of primary key within the <see cref="Record"/>.</param>
        /// <returns>The sequence of <see cref="Entity"/> instances.</returns>
        public static IEnumerable <Entity> ToEntities(this RecordSetReader source, int primaryKeyIndex)
        {
            var session = ((EnumerationContext)source.Context).Session;
            var reader  = session.Domain.EntityDataReader;

            foreach (var record in reader.Read(source.ToEnumerable(), source.Header, session))
            {
                var key = record.GetKey(primaryKeyIndex);
                if (key == null)
                {
                    continue;
                }
                var tuple = record.GetTuple(primaryKeyIndex);
                if (tuple != null)
                {
                    yield return(session.Handler.UpdateState(key, tuple).Entity);
                }
                else
                {
                    yield return(session.Query.SingleOrDefault(key));
                }
            }
        }
示例#4
0
 /// <summary>
 /// Converts the <see cref="RecordSetReader"/> items to <see cref="Entity"/> instances.
 /// </summary>
 /// <typeparam name="T">The type of <see cref="Entity"/> instances to get.</typeparam>
 /// <param name="source">The <see cref="RecordSetReader"/> to process.</param>
 /// <param name="primaryKeyIndex">Index of primary key within the <see cref="Record"/>.</param>
 /// <returns>The sequence of <see cref="Entity"/> instances.</returns>
 public static IEnumerable <T> ToEntities <T>(this RecordSetReader source, int primaryKeyIndex)
     where T : class, IEntity =>
 ToEntities(source, primaryKeyIndex).Cast <T>();