当前位置: 首页>>代码示例>>C#>>正文


C# ODataQueryOptions.ApplyTo方法代码示例

本文整理汇总了C#中ODataQueryOptions.ApplyTo方法的典型用法代码示例。如果您正苦于以下问题:C# ODataQueryOptions.ApplyTo方法的具体用法?C# ODataQueryOptions.ApplyTo怎么用?C# ODataQueryOptions.ApplyTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ODataQueryOptions的用法示例。


在下文中一共展示了ODataQueryOptions.ApplyTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTeams

        public IQueryable<Team> GetTeams(ODataQueryOptions queryOptions)
        {
            // Validate query options
            var settings = new ODataValidationSettings()
            {
                MaxTop = 400
            };
            queryOptions.Validate(settings);

            // Apply the filter before going through to check if links exist for significant performance improvements
            var teams = (IQueryable<Team>)queryOptions.ApplyTo(Db.core.Teams);

            // RouteLinker creates Uris for actions
            var linker = new RouteLinker(Request);

            foreach (var team in teams)
            {
                if (team.Links == null)
                {
                    team.Links = new SerializableDynamic();
                    team.Links.url = linker.GetUri<TeamsController>(c => c.GetTeam(team.Number)).ToString();
                }
            }

            var nextRequest = Request.RequestUri;

            return Db.core.Teams.AsQueryable();
        }
开发者ID:vexteamnet,项目名称:ApiApp,代码行数:28,代码来源:TeamsController.cs

示例2: Get

 public IHttpActionResult Get(ODataQueryOptions<ODataQueryOptionTest_EntityModel> queryOptions)
 {
     // Don't apply Filter and Expand, but apply Select.
     var appliedQueryOptions = AllowedQueryOptions.Skip | AllowedQueryOptions.Filter | AllowedQueryOptions.Expand;
     var res = queryOptions.ApplyTo(_entityModels, appliedQueryOptions);
     return Ok(res.AsQueryable());
 }
开发者ID:genusP,项目名称:WebApi,代码行数:7,代码来源:ODataQueryOptionTest.cs

示例3: GetFromManager

        // Pass ODataQueryOptions as parameter, and call validation manually
        public IHttpActionResult GetFromManager(ODataQueryOptions<Manager> queryOptions)
        {
            if (queryOptions.SelectExpand != null)
            {
                queryOptions.SelectExpand.LevelsMaxLiteralExpansionDepth = 5;
            }

            var validationSettings = new ODataValidationSettings { MaxExpansionDepth = 5 };

            try
            {
                queryOptions.Validate(validationSettings);
            }
            catch (ODataException e)
            {
                var responseMessage = new HttpResponseMessage(HttpStatusCode.BadRequest);
                responseMessage.Content = new StringContent(
                    string.Format("The query specified in the URI is not valid. {0}", e.Message));
                return ResponseMessage(responseMessage);
            }

            var querySettings = new ODataQuerySettings();
            var result = queryOptions.ApplyTo(_employees.OfType<Manager>().AsQueryable(), querySettings).AsQueryable();
            return Ok(result, result.GetType());
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:26,代码来源:EmployeesController.cs

示例4: GetCustomers

        public IEnumerable<Customer> GetCustomers(ODataQueryOptions<Customer> queryOptions)
        {
            // validate the query.
            queryOptions.Validate(_validationSettings);

            // Apply the query.
            IQuery query = queryOptions.ApplyTo(_db);

            Console.WriteLine("Executing HQL:\t" + query);
            Console.WriteLine();

            return query.List<Customer>();
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:13,代码来源:CustomersController.cs

示例5: GetImages

        // GET: odata/Images
        public PageResult<Image> GetImages(ODataQueryOptions<Image> options)
        {
            ODataQuerySettings settings = new ODataQuerySettings()
            {
                PageSize = CollectionOfWorkers.SizeOfPage
            };

            IQueryable results = options.ApplyTo(db.Images.AsQueryable(), settings);

            return new PageResult<Image>(
                results as IEnumerable<Image>,
                null,
                db.Images.Count());
        }
开发者ID:XDIM2006,项目名称:OfiiceWithMSMQ-and-WinService,代码行数:15,代码来源:ImagesController.cs

示例6: Get

 public IHttpActionResult Get(ODataQueryOptions<AttributedSelectExpandCustomer> options)
 {
     IQueryable result = options.ApplyTo(Enumerable.Range(1, 10).Select(i => new AttributedSelectExpandCustomer
     {
         Id = i,
         Name = "Name " + i,
         Orders = Enumerable.Range(1, 10).Select(j => new AttributedSelectExpandOrder
         {
             CustomerName = "Customer Name" + j,
             Id = j,
             Total = i * j
         }).ToList()
     }).AsQueryable());
     return Ok(result);
 }
开发者ID:akrisiun,项目名称:WebApi,代码行数:15,代码来源:SelectExpandTest.cs

示例7: Get

        // GET: Domains
        public IEnumerable<DomainsProjection> Get(ODataQueryOptions<DomainsProjection> options)
        {
            var querySettings = new ODataQuerySettings()
            {
                EnableConstantParameterization = true,
                EnsureStableOrdering = true
            };

            var raw = GetDomains().OrderBy(d => d.HostName);
            var total = options.Filter == null ? raw.Count() : options.Filter.ApplyTo(raw, querySettings).Count();
            var res = (IQueryable<DomainsProjection>) options.ApplyTo(raw, querySettings);

            return new PageResult<DomainsProjection>(res, options.GetNextLink(total), total);

            //return GetDomains().ToArray();
        }
开发者ID:c0d3m0nky,项目名称:mty,代码行数:17,代码来源:DomainsController.cs

示例8: Get

        // Note this can be done through Queryable attribute as well
        public IQueryable<Order> Get(ODataQueryOptions queryOptions)
        {
            // Register a custom FilterByValidator to disallow custom logic in the filter query
            if (queryOptions.Filter != null)
            {
                queryOptions.Filter.Validator = new RestrictiveFilterByQueryValidator();
            }

            // Validate the query, we only allow order by Id property and
            // we only allow maximum Top query value to be 9
            ODataValidationSettings settings = new ODataValidationSettings() { MaxTop = 9 };
            settings.AllowedOrderByProperties.Add("Id");
            queryOptions.Validate(settings);

            // Apply the query
            return queryOptions.ApplyTo(OrderList.AsQueryable()) as IQueryable<Order>;
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:18,代码来源:OrdersController.cs

示例9: FindJobs

        internal async Task<QueryResult<Job>> FindJobs(ODataQueryOptions<Job> query, int start, int limit)
        {
            return await Task.Run(() =>
            {
                IQueryable queryResult;
                queryResult = query.ApplyTo(_context.Jobs.AsQueryable(), AllowedQueryOptions.OrderBy);
                if (query.OrderBy != null)
                    queryResult = queryResult.LinqToQuerystring(typeof(Job), "$orderby=" + query.OrderBy.RawValue) as IQueryable<Job>;

                var data = queryResult as IEnumerable<Job>;

                if (query.Count != null && query.Count.Value)
                    return new QueryResult<Job>(null, data.LongCount());
                else
                    return new QueryResult<Job>(data.Skip(start).Take(limit), data.LongCount());
            });
        }
开发者ID:NerdCats,项目名称:TaskCat,代码行数:17,代码来源:JobStore.cs

示例10: Get

        public IHttpActionResult Get(ODataQueryOptions<DLManager> queryOptions)
        {
            ODataValidationSettings settings = new ODataValidationSettings();
            settings.MaxExpansionDepth = 1;

            try
            {
                queryOptions.Validate(settings);
            }
            catch (ODataException e)
            {
                var responseMessage = new HttpResponseMessage(HttpStatusCode.BadRequest);
                responseMessage.Content = new StringContent(
                    String.Format("The query specified in the URI is not valid. {0}", e.Message));
                return ResponseMessage(responseMessage);
            }

            var managers = queryOptions.ApplyTo(_DLManagers.AsQueryable()).AsQueryable();
            return Ok(managers, managers.GetType());
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:20,代码来源:DollarLevelsController.cs

示例11: GetRecipeAsync

        // GET: api/Recipes
        public async Task<IQueryable<Recipe>> GetRecipeAsync(ODataQueryOptions options)
        {
            var appUser = await AuthRepo.FindUserByName(User.Identity.Name);

            IQueryable results = options.ApplyTo(MatsMatRepo.GetAllRecipes());
          //IQueryable results = MatsMatRepo.GetAllRecipes();
            var result = results as IQueryable<Recipe>;
      
            var paginationHeader = new
            {
                TotalCount = Request.ODataProperties().TotalCount,
                Skip = options?.Skip?.Value ?? 0,
                Top = options?.Top?.Value ?? 0,
                Url = ""
            };

            //Add pagination info to response header
            System.Web.HttpContext.Current.Response.AddHeader("Access-Control-Expose-Headers", "X-Pagination");
            System.Web.HttpContext.Current.Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader));           

            return result;
        }
开发者ID:laumsporre,项目名称:matsmat,代码行数:23,代码来源:RecipesController.cs

示例12: ApplyTo_Entity_ThrowsInvalidOperation_IfNonSelectExpand

        public void ApplyTo_Entity_ThrowsInvalidOperation_IfNonSelectExpand(string parameter)
        {
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            model.Model.SetAnnotationValue(model.Customer, new ClrTypeAnnotation(typeof(Customer)));
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost?" + parameter);
            ODataQueryContext context = new ODataQueryContext(model.Model, typeof(Customer));
            ODataQueryOptions queryOptions = new ODataQueryOptions(context, request);

            Assert.Throws<InvalidOperationException>(
                () => queryOptions.ApplyTo(42, new ODataQuerySettings()),
                "The requested resource is not a collection. Query options $filter, $orderby, $count, $skip, and $top can be applied only on collections.");
        }
开发者ID:shailendra9,项目名称:WebApi,代码行数:12,代码来源:ODataQueryOptionTest.cs

示例13: ApplyTo_Entity_ThrowsArgumentNull_QuerySettings

        public void ApplyTo_Entity_ThrowsArgumentNull_QuerySettings()
        {
            ODataQueryContext context = new ODataQueryContext(EdmCoreModel.Instance, typeof(int));
            ODataQueryOptions queryOptions = new ODataQueryOptions(context, new HttpRequestMessage());

            Assert.ThrowsArgumentNull(
                () => queryOptions.ApplyTo(entity: 42, querySettings: null),
                "querySettings");
        }
开发者ID:shailendra9,项目名称:WebApi,代码行数:9,代码来源:ODataQueryOptionTest.cs

示例14: ApplyTo_IgnoresCount_IfRequestAlreadyHasCount

        public void ApplyTo_IgnoresCount_IfRequestAlreadyHasCount()
        {
            // Arrange
            long count = 42;
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/?$count=true");
            ODataQueryContext context = new ODataQueryContext(EdmCoreModel.Instance, typeof(int));
            ODataQueryOptions options = new ODataQueryOptions(context, request);
            request.ODataProperties().TotalCount = count;

            // Act
            options.ApplyTo(Enumerable.Empty<int>().AsQueryable());

            // Assert
            Assert.Equal(count, request.ODataProperties().TotalCount);
        }
开发者ID:shailendra9,项目名称:WebApi,代码行数:15,代码来源:ODataQueryOptionTest.cs

示例15: ODataQueryOptions_IgnoresUnknownOperatorStartingWithDollar

        public void ODataQueryOptions_IgnoresUnknownOperatorStartingWithDollar()
        {
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/?$filter=$it eq 6&$unknown=value");
            ODataQueryContext context = new ODataQueryContext(EdmCoreModel.Instance, typeof(int));
            ODataQueryOptions options = new ODataQueryOptions(context, request);

            var queryable = options.ApplyTo(Enumerable.Range(0, 10).AsQueryable());

            IEnumerator enumerator = queryable.GetEnumerator();
            Assert.True(enumerator.MoveNext());
            Assert.Equal(6, enumerator.Current);
        }
开发者ID:shailendra9,项目名称:WebApi,代码行数:12,代码来源:ODataQueryOptionTest.cs


注:本文中的ODataQueryOptions.ApplyTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。