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


C# ODataQueryOptions.ApplyTo方法代码示例

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


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

示例1: GetOrders

        // GET: odata/Orders
        public async Task<IHttpActionResult> GetOrders(ODataQueryOptions<Order> queryOptions)
        {
            // validate the query.
            try
            {
                queryOptions.Validate(_validationSettings);
            }
            catch (ODataException ex)
            {
                return BadRequest(ex.Message);
            }

            var repository = new Repositories.OrderMemoryRepository();
            var orders = queryOptions.ApplyTo(repository.Get().AsQueryable<Order>());

            return Ok<IQueryable<Order>>((IQueryable<Order>)orders);
        }
开发者ID:SergeyDushkin,项目名称:test,代码行数:18,代码来源:OrdersController.cs

示例2: GetCategoryTrees

        public async Task<IHttpActionResult> GetCategoryTrees(ODataQueryOptions<CategoryTree> queryOptions)
        {
            logger.Trace("Call CategoryTreesController GetCategoryTrees");

            try
            {
                queryOptions.Validate(_validationSettings);
            }
            catch (ODataException ex)
            {
                return BadRequest(ex.Message);
            }

            var data = await repository.All();

            var query = (IQueryable<CategoryTree>)queryOptions
                .ApplyTo(data.AsQueryable());

            return Ok(query);
        }
开发者ID:SergeyDushkin,项目名称:test,代码行数:20,代码来源:CategoryTreesController.cs

示例3: GetCount

        public HttpResponseMessage GetCount(ODataQueryOptions<ODataPackage> options)
        {
            var queryResults = (IQueryable<ODataPackage>)options.ApplyTo(Get());
            var count = queryResults.Count();

            return OkCount(count);
        }
开发者ID:jjchiw,项目名称:NuGet.Lucene,代码行数:7,代码来源:PackagesODataController.cs

示例4: Get

 public IQueryable<ProductType> Get(ODataQueryOptions<Domain.ProductType> paramters)
 {
     var resultset = paramters.ApplyTo(_db.ProductTypes).AsQueryable() as IQueryable<Domain.ProductType>;
     // ReSharper disable once AssignNullToNotNullAttribute
     var productTypes = resultset.ToArray().Select(Mapper.Map<ProductType>).AsQueryable();
     return productTypes;
 }
开发者ID:cberberian,项目名称:GameSim,代码行数:7,代码来源:ProductTypeController.cs

示例5: IsHijackable

        public static bool IsHijackable(ODataQueryOptions<V2FeedPackage> options, out HijackableQueryParameters hijackable)
        {
            // Check if we can process the filter clause
            if (!CanProcessFilterClause(options))
            {
                hijackable = null;
                return false;
            }

            // Build expression (this works around all internal classes in the OData library - all we want is an expression tree)
            var expression = options.ApplyTo(EmptyQueryable, QueryResultDefaults.DefaultQuerySettings).Expression;

            // Unravel the comparisons into a list we can reason about
            List<Tuple<Target, string>> comparisons = new List<Tuple<Target, string>>();
            Expression remnant = FindQueryableWhere(expression as MethodCallExpression);
            MethodCallExpression where;
            while (IsQueryableWhere(where = remnant as MethodCallExpression))
            {
                var extractedComparisons = ExtractComparison(where).ToList();
                if (!extractedComparisons.Any() || extractedComparisons.Any(c => c == null))
                {
                    hijackable = null;
                    return false;
                }
                else
                {
                    // We recognize this comparison, record it and keep iterating on the nested expression
                    comparisons.AddRange(extractedComparisons);
                    remnant = where.Arguments[0];
                }
            }

            // We should be able to hijack here
            if (comparisons.Any())
            {
                hijackable = new HijackableQueryParameters();
                foreach (var comparison in comparisons)
                {
                    if (comparison.Item1 == Target.Id)
                    {
                        hijackable.Id = comparison.Item2;
                    }
                    else if (comparison.Item1 == Target.Version)
                    {
                        hijackable.Version = comparison.Item2;
                    }
                    else
                    {
                        hijackable = null;
                        return false;
                    }
                }

                return true;
            }

            hijackable = null;
            return false;
        }
开发者ID:rhysawilliams2010,项目名称:NuGetGallery,代码行数:59,代码来源:SearchHijacker.cs

示例6: GetSalesLeads

        public IHttpActionResult GetSalesLeads(ODataQueryOptions<SalesLead> queryOptions)
        {
            try { queryOptions.Validate(_validationSettings); }
              catch (ODataException ex) { return BadRequest(ex.Message); }

              var queryResults = queryOptions.ApplyTo(SalesLeadFactory.GetSalesLeads()).Cast<SalesLead>();

              return Ok<IQueryable<SalesLead>>(queryResults);
        }
开发者ID:CriticalPathTraining,项目名称:CBD365,代码行数:9,代码来源:SalesLeadsController.cs

示例7: Get

        // GET api/buildingupgrade
        public IQueryable<BuildingUpgrade> Get(ODataQueryOptions<Domain.BuildingUpgrade> paramters)
        {
            var logStart = LogHelper.StartLog("Started BuildingUpgradeController.Get", Logger);
            var resultset = paramters.ApplyTo(_db.BuildingUpgrades).AsQueryable() as IQueryable<Domain.BuildingUpgrade>;
            // ReSharper disable once AssignNullToNotNullAttribute

            var buildingUpgrades = resultset.ToArray().Where(x=>x.Name.StartsWith("Property") && x.Completed == false).OrderBy(x=>x.Name). Select(Mapper.Map<BuildingUpgrade>).AsQueryable();
            return LogHelper.EndLog(logStart, buildingUpgrades);
        }
开发者ID:cberberian,项目名称:GameSim,代码行数:10,代码来源:BuildingUpgradeController.cs

示例8: GetPurchaseRequisitionDescriptions

        // GET api/PurchaseRequisitionDescription
        public IEnumerable<PurchaseRequisitionDescription> GetPurchaseRequisitionDescriptions(ODataQueryOptions Options)
        {
            //return db.PurchaseRequisitionDescriptions.Include(p=>p.Product).AsEnumerable();
            //return Options.ApplyTo(db.PurchaseRequisitionDescriptions.Include(p => p.Product) as IQueryable) as IEnumerable<PurchaseRequisitionDescription>;

            //db.PurchaseRequisitionDescriptions.Include(p => p.Product).Include()

            return Options.ApplyTo(db.PurchaseRequisitionDescriptions.AsQueryable().Include(p => p.Product).Include(p => p.Product.ProductCategory).Include(u => u.UOM)) as IEnumerable<PurchaseRequisitionDescription>;
        }
开发者ID:daradbd,项目名称:BMS,代码行数:10,代码来源:PurchaseRequisitionDescriptionController.cs

示例9: CountSearch

        public HttpResponseMessage CountSearch(
            [FromODataUri] string searchTerm,
            [FromODataUri] string targetFramework,
            [FromODataUri] bool includePrerelease,
            ODataQueryOptions<ODataPackage> options)
        {
            var queryResults = (IQueryable<ODataPackage>)options.ApplyTo(Search(searchTerm, targetFramework, includePrerelease, options));
            var count = queryResults.Count();

            return OkCount(count);
        }
开发者ID:jjchiw,项目名称:NuGet.Lucene,代码行数:11,代码来源:PackagesODataController.cs

示例10: ApplyTo_Succeeds_If_QueryTypeMatchesOptionsType

        public void ApplyTo_Succeeds_If_QueryTypeMatchesOptionsType()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Customer>("Customers");

            ODataQueryContext context = new ODataQueryContext(builder.GetEdmModel(), typeof(Customer));

            ODataQueryOptions<Customer> query = new ODataQueryOptions<Customer>(context, new HttpRequestMessage(HttpMethod.Get, "http://server/?$top=10"));

            Assert.DoesNotThrow(
                () => query.ApplyTo(Enumerable.Empty<Customer>().AsQueryable()));
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:12,代码来源:ODataQueryOptionsOfTEntityTest.cs

示例11: ApplyTo_ThrowsInvalidOp_If_QueryTypeDoesnotMatch

        public void ApplyTo_ThrowsInvalidOp_If_QueryTypeDoesnotMatch()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Customer>("Customers");

            ODataQueryContext context = new ODataQueryContext(builder.GetEdmModel(), typeof(Customer));

            ODataQueryOptions<Customer> query = new ODataQueryOptions<Customer>(context, new HttpRequestMessage(HttpMethod.Get, "http://server/?$top=10"));

            Assert.Throws<InvalidOperationException>(
                () => query.ApplyTo(Enumerable.Empty<int>().AsQueryable()),
                "Cannot apply ODataQueryOptions of 'System.Web.Http.OData.TestCommon.Models.Customer' to IQueryable of 'System.Int32'.");
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:13,代码来源:ODataQueryOptionsOfTEntityTest.cs

示例12: Get

        public IQueryable<LessonViewModel> Get(ODataQueryOptions<LessonViewModel> queryOptions)
        {
            var result =  _lessonService.GetLessons().Select(l => new LessonViewModel
            {
                Date = l.Date,
                GroupId = l.Group.GroupId,
                LessonId = l.LessonId,
                GroupDisplayName = l.Group.GroupNumber + " (" + l.Group.Year + ")"
            });

            var filteredResult = ((IQueryable<LessonViewModel>)queryOptions.ApplyTo(result));
            return filteredResult;
        }
开发者ID:WadeOne,项目名称:EasyTeach,代码行数:13,代码来源:LessonsController.cs

示例13: GetOrders

        public PageResult<Order> GetOrders(ODataQueryOptions<Order> options)
        {
            var settings = new ODataQuerySettings();

            var fromDatabase = _context.Orders.Where(order => order.Freight != 123);

            var results = options.ApplyTo(fromDatabase.AsQueryable(), settings);

            return new PageResult<Order>(
                results as IQueryable<Order>,
                Request.ODataProperties().NextLink,
                Request.ODataProperties().TotalCount);
        }
开发者ID:denhul,项目名称:KendoUiWithApiControllers,代码行数:13,代码来源:KendoUiSampleController.cs

示例14: GetFacets

        public IQueryable<Facet> GetFacets(ODataQueryOptions<Car> options)
        {
            if (options.RawValues.Expand.IsNullOrEmpty())
            {
                return new Facet[0].AsQueryable();
            }

            IQueryable results = options.ApplyTo(SearchContext.GetQueryable<Car>());
            string[] facets = StringUtil.Split(options.RawValues.Expand, '|', true);
            var query = results as IQueryable<Car>;

            return SearchService.GetFacets(query, facets);
        }
开发者ID:alexlapinski,项目名称:autohaus,代码行数:13,代码来源:FacetController.cs

示例15: 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


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