예제 #1
0
        public IHttpActionResult Filter([FromUri(Name = "")] QuerySamplesRequest request)
        {
            Logger.Trace("Fetching samples.");

            if (request == null)
            {
                request = new QuerySamplesRequest();
            }

            if (request.Name == "badrequest")
            {
                return(InvalidRequest("Dude, that's a bad request.", "ValidationError"));
            }

            QuerySamplesResponse response;

            using (var context = new SampleDataContext())
            {
                IQueryable <Sample> query = context.Samples;

                if (!String.IsNullOrEmpty(request.Name))
                {
                    query = query.Where(s => s.Name == request.Name);
                }

                response = new QuerySamplesResponse(query.WithNoLock(q => q.Select(request.Fields).ToPage(request)));
            }

            return(Ok(response));
        }
예제 #2
0
        public async Task <IHttpActionResult> Filter([FromUri(Name = "")] QuerySamplesRequest request)
        {
            if (request == null)
            {
                request = new QuerySamplesRequest();
            }

            if (request.Name == "badrequest")
            {
                return(InvalidRequest("Dude, that's a bad request.", "ValidationError"));
            }

            QuerySamplesResponse response;

            using (var context = new SampleDataContext())
            {
                IQueryable <Sample> query = context.Samples;

                if (!String.IsNullOrEmpty(request.Name))
                {
                    query = query.Where(s => s.Name == request.Name);
                }

                var page = await query.WithNoLock(q => q.Select(request.Fields).ToPageAsync(request));

                return(Page(page));
            }

            return(Ok(response));
        }
예제 #3
0
        public QuerySamplesResponse QuerySamples(QuerySamplesRequest request)
        {
            QuerySamplesResponse response = new QuerySamplesResponse(null);

            _sampleRepository.QuerySamples(request.Fields, request.Name);

            return(response);
        }
예제 #4
0
        public IActionResult QuerySamples([FromQuery] QuerySamplesRequest request)
        {
            List <Sample> samples = new List <Sample>();

            for (int i = 0; i < 100; i++)
            {
                samples.Add(CreateNewSample());
            }

            return(Page(samples.AsQueryable().Select(request.Fields).ToPage(request)));
        }
        public void Get_ShouldReturnEntity_WhenIdAndNameRequested()
        {
            SampleController controller = new SampleController(null, null, null);

            Stopwatch watch = Stopwatch.StartNew();

            var request = new QuerySamplesRequest()
            {
                Fields = "id,name"
            };

            for (int i = 0; i < 20000; i++)
            {
                var result = controller.Filter(request);
            }

            long elapsed = watch.ElapsedMilliseconds;

            Console.WriteLine(elapsed);
        }