public override async Task <IDataReaderAsync> ExecuteReaderAsync(CancellationToken cancellationToken)
            {
                if (_dataContext._batchCounter > 0)
                {
                    throw new LinqException("Incompatible batch operation.");
                }

                string data;

                SetCommand(true);

                var queryContext = Query.Queries[QueryNumber];

                var q = _dataContext.GetSqlOptimizer().PrepareStatementForRemoting(queryContext.Statement, _dataContext.MappingSchema, _evaluationContext);
                var currentParameters = q.CollectParameters();

                data = LinqServiceSerializer.Serialize(
                    _dataContext.SerializationMappingSchema,
                    q,
                    currentParameters,
                    _evaluationContext.ParameterValues,
                    QueryHints);

                _client = _dataContext.GetClient();

                var ret = await _client.ExecuteReaderAsync(_dataContext.Configuration, data).ConfigureAwait(Common.Configuration.ContinueOnCapturedContext);

                var result = LinqServiceSerializer.DeserializeResult(_dataContext.SerializationMappingSchema, ret);
                var reader = new ServiceModelDataReader(_dataContext.SerializationMappingSchema, result);

                return(new DataReaderAsync(reader));
            }
            public override async Task <IDataReaderAsync> ExecuteReaderAsync(CancellationToken cancellationToken)
            {
                if (_dataContext._batchCounter > 0)
                {
                    throw new LinqException("Incompatible batch operation.");
                }

                SetCommand(true);

                var queryContext = Query.Queries[QueryNumber];

                _client = _dataContext.GetClient();

                var q   = _dataContext.GetSqlOptimizer().OptimizeStatement(queryContext.Statement, _dataContext.MappingSchema);
                var ret = await _client.ExecuteReaderAsync(
                    _dataContext.Configuration,
                    LinqServiceSerializer.Serialize(
                        q,
                        q.IsParameterDependent ? q.Parameters.ToArray() : queryContext.GetParameters(),
                        QueryHints));

                var result = LinqServiceSerializer.DeserializeResult(ret);
                var reader = new ServiceModelDataReader(_dataContext.MappingSchema, result);

                return(new DataReaderAsync(reader));
            }
                public async Task QueryForEachAsync <T>(Func <IDataReader, T> objectReader, Func <T, bool> action, CancellationToken cancellationToken)
                {
                    _dataContext.ThrowOnDisposed();

                    await TaskEx.Run(() =>
                    {
                        var result = LinqServiceSerializer.DeserializeResult(_result);

                        using (var reader = new ServiceModelDataReader(_dataContext.MappingSchema, result))
                        {
                            var skip = _skipAction?.Invoke() ?? 0;

                            while (skip-- > 0 && reader.Read())
                            {
                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }
                            }

                            var take = _takeAction?.Invoke() ?? int.MaxValue;

                            while (take-- > 0 && reader.Read())
                            {
                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }
                                else
                                if (!action(objectReader(reader)))
                                {
                                    return;
                                }
                            }
                        }
                    },
                                     cancellationToken);
                }
 public DataReaderAsync(ServiceModelDataReader dataReader)
 {
     DataReader = dataReader;
 }