示例#1
0
        public void Fill(Dictionary <LookupToken, IEnumerable> lookups, IRetriever retriever)
        {
            using (HeavyProfiler.Log("SQL", () => Command.Sql))
                using (DbDataReader reader = Executor.UnsafeExecuteDataReader(Command))
                {
                    ProjectionRowEnumerator <KeyValuePair <K, V> > enumerator = new ProjectionRowEnumerator <KeyValuePair <K, V> >(reader, ProjectorExpression, lookups, retriever);

                    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)
                    {
                        FieldReaderException fieldEx = enumerator.Reader.CreateFieldReaderException(ex);
                        fieldEx.Command   = Command;
                        fieldEx.Row       = enumerator.Row;
                        fieldEx.Projector = ProjectorExpression;
                        throw fieldEx;
                    }
                }
        }
示例#2
0
        public async Task FillAsync(Dictionary <LookupToken, IEnumerable> lookups, IRetriever retriever, CancellationToken token)
        {
            using (HeavyProfiler.Log("SQL", () => Command.Sql))
                using (DbDataReader reader = await Executor.UnsafeExecuteDataReaderAsync(Command, token: token))
                {
                    ProjectionRowEnumerator <KeyValuePair <K, V> > enumerator = new ProjectionRowEnumerator <KeyValuePair <K, V> >(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;
                    }
                }
        }
示例#3
0
        public async Task <object> ExecuteAsync(CancellationToken token)
        {
            using (new EntityCache())
                using (Transaction tr = new Transaction())
                {
                    object result;
                    using (var retriever = EntityCache.NewRetriever())
                    {
                        if (EagerProjections.Any() || LazyChildProjections.Any())
                        {
                            lookups = new Dictionary <LookupToken, IEnumerable>();
                        }

                        foreach (var child in EagerProjections)
                        {
                            child.Fill(lookups, retriever);
                        }

                        using (HeavyProfiler.Log("SQL", () => MainCommand.PlainSql()))
                            using (DbDataReader reader = await Executor.UnsafeExecuteDataReaderAsync(MainCommand, token: token))
                            {
                                ProjectionRowEnumerator <T> enumerator = new ProjectionRowEnumerator <T>(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)
                        {
                            child.Fill(lookups, retriever);
                        }

                        retriever.CompleteAll();
                    }

                    return(tr.Commit(result));
                }
        }
示例#4
0
        public object?Execute()
        {
            return(SqlServerRetry.Retry(() =>
            {
                using (new EntityCache())
                    using (Transaction tr = new Transaction())
                    {
                        object?result;
                        using (var retriever = EntityCache.NewRetriever())
                        {
                            var lookups = new Dictionary <LookupToken, IEnumerable>();

                            foreach (var child in EagerProjections)
                            {
                                child.Fill(lookups, retriever);
                            }

                            using (HeavyProfiler.Log("SQL", () => MainCommand.sp_executesql()))
                                using (var reader = Executor.UnsafeExecuteDataReader(MainCommand))
                                {
                                    ProjectionRowEnumerator <T> enumerator = new ProjectionRowEnumerator <T>(reader.Reader, ProjectorExpression, lookups, retriever, CancellationToken.None);

                                    IEnumerable <T> enumerable = new ProjectionRowEnumerable <T>(enumerator);

                                    try
                                    {
                                        if (Unique == null)
                                        {
                                            result = enumerable.ToList();
                                        }
                                        else
                                        {
                                            result = UniqueMethod(enumerable, Unique.Value);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        FieldReaderException fieldEx = enumerator.Reader.CreateFieldReaderException(ex);
                                        fieldEx.Command = MainCommand;
                                        fieldEx.Row = enumerator.Row;
                                        fieldEx.Projector = ProjectorExpression;
                                        throw fieldEx;
                                    }
                                }

                            foreach (var child in LazyChildProjections)
                            {
                                child.Fill(lookups, retriever);
                            }

                            retriever.CompleteAll();
                        }

                        return tr.Commit(result);
                    }
            }));
        }
示例#5
0
        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.Sql))
                using (DbDataReader reader = await Executor.UnsafeExecuteDataReaderAsync(Command, token: token))
                {
                    ProjectionRowEnumerator <KeyValuePair <K, MList <V> .RowIdElement> > enumerator = new ProjectionRowEnumerator <KeyValuePair <K, MList <V> .RowIdElement> >(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).InnerList.AddRange(results);
                            ((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;
                    }
                }
        }