public async Task FillAsync(Dictionary <LookupToken, IEnumerable> lookups, IRetriever retriever, CancellationToken token) { using (HeavyProfiler.Log("SQL", () => Command.sp_executesql())) using (var reader = await Executor.UnsafeExecuteDataReaderAsync(Command, token: token)) { ProjectionRowEnumerator <KeyValuePair <K, V> > enumerator = new ProjectionRowEnumerator <KeyValuePair <K, V> >(reader.Reader, ProjectorExpression, lookups, retriever, token); IEnumerable <KeyValuePair <K, V> > enumerabe = new ProjectionRowEnumerable <KeyValuePair <K, V> >(enumerator); try { var lookUp = enumerabe.ToLookup(a => a.Key, a => a.Value); lookups.Add(Token, lookUp); } catch (Exception ex) when(!(ex is OperationCanceledException)) { FieldReaderException fieldEx = enumerator.Reader.CreateFieldReaderException(ex); fieldEx.Command = Command; fieldEx.Row = enumerator.Row; fieldEx.Projector = ProjectorExpression; throw fieldEx; } } }
public Task <object?> ExecuteAsync(CancellationToken token) { return(SqlServerRetry.RetryAsync(async() => { using (new EntityCache()) using (var tr = new Transaction()) { object?result; using (var retriever = EntityCache.NewRetriever()) { var lookups = new Dictionary <LookupToken, IEnumerable>(); foreach (var child in EagerProjections) { await child.FillAsync(lookups, retriever, token); } using (HeavyProfiler.Log("SQL", () => MainCommand.sp_executesql())) using (var reader = await Executor.UnsafeExecuteDataReaderAsync(MainCommand, token: token)) { ProjectionRowEnumerator <T> enumerator = new ProjectionRowEnumerator <T>(reader.Reader, ProjectorExpression, lookups, retriever, token); IEnumerable <T> enumerable = new ProjectionRowEnumerable <T>(enumerator); try { if (Unique == null) { result = enumerable.ToList(); } else { result = UniqueMethod(enumerable, Unique.Value); } } catch (Exception ex) when(!(ex is OperationCanceledException)) { FieldReaderException fieldEx = enumerator.Reader.CreateFieldReaderException(ex); fieldEx.Command = MainCommand; fieldEx.Row = enumerator.Row; fieldEx.Projector = ProjectorExpression; throw fieldEx; } } foreach (var child in LazyChildProjections) { await child.FillAsync(lookups, retriever, token); } retriever.CompleteAll(); } return tr.Commit(result); } })); }
public async Task FillAsync(Dictionary <LookupToken, IEnumerable> lookups, IRetriever retriever, CancellationToken token) { Dictionary <K, MList <V> >?requests = (Dictionary <K, MList <V> >?)lookups.TryGetC(Token); if (requests == null) { return; } using (HeavyProfiler.Log("SQL", () => Command.sp_executesql())) using (var reader = await Executor.UnsafeExecuteDataReaderAsync(Command, token: token)) { ProjectionRowEnumerator <KeyValuePair <K, MList <V> .RowIdElement> > enumerator = new ProjectionRowEnumerator <KeyValuePair <K, MList <V> .RowIdElement> >(reader.Reader, ProjectorExpression, lookups, retriever, token); IEnumerable <KeyValuePair <K, MList <V> .RowIdElement> > enumerabe = new ProjectionRowEnumerable <KeyValuePair <K, MList <V> .RowIdElement> >(enumerator); try { var lookUp = enumerabe.ToLookup(a => a.Key, a => a.Value); foreach (var kvp in requests) { var results = lookUp[kvp.Key]; ((IMListPrivate <V>)kvp.Value).AssignMList(results.ToList()); ((IMListPrivate <V>)kvp.Value).InnerListModified(results.Select(a => a.Element).ToList(), null); retriever.ModifiablePostRetrieving(kvp.Value); } } catch (Exception ex) when(!(ex is OperationCanceledException)) { FieldReaderException fieldEx = enumerator.Reader.CreateFieldReaderException(ex); fieldEx.Command = Command; fieldEx.Row = enumerator.Row; fieldEx.Projector = ProjectorExpression; throw fieldEx; } } }
internal ProjectionRowEnumerable(ProjectionRowEnumerator <T> enumerator) { this.enumerator = enumerator; }