public void Fill(Dictionary <LookupToken, IEnumerable> lookups, IRetriever retriever) { Dictionary <K, MList <V> > requests = (Dictionary <K, MList <V> >)lookups.TryGetC(Token); if (requests == null) { return; } using (HeavyProfiler.Log("SQL", () => Command.PlainSql())) using (DbDataReader reader = Executor.UnsafeExecuteDataReader(Command)) { ProjectionRowEnumerator <KeyValuePair <K, MList <V> .RowIdElement> > enumerator = new ProjectionRowEnumerator <KeyValuePair <K, MList <V> .RowIdElement> >(reader, ProjectorExpression, lookups, retriever, CancellationToken.None); 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).InnerList.AddRange(results); ((IMListPrivate <V>)kvp.Value).InnerListModified(results.Select(a => a.Element).ToList(), null); retriever.ModifiablePostRetrieving(kvp.Value); } } catch (Exception ex) { FieldReaderException fieldEx = enumerator.Reader.CreateFieldReaderException(ex); fieldEx.Command = Command; fieldEx.Row = enumerator.Row; fieldEx.Projector = ProjectorExpression; throw fieldEx; } } }
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; } } }