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


C# ODataQueryOptions.Validate方法代码示例

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


在下文中一共展示了ODataQueryOptions.Validate方法的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: 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

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

示例4: GetOrder

        // GET: odata/Orders(5)
        public IHttpActionResult GetOrder([FromODataUri] int key, ODataQueryOptions<Order> queryOptions)
        {
            // validate the query.
            try
            {
                queryOptions.Validate(_validationSettings);
            }
            catch (ODataException ex)
            {
                return BadRequest(ex.Message);
            }

            // return Ok<Order>(order);
            return StatusCode(HttpStatusCode.NotImplemented);
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:16,代码来源:OrdersController.cs

示例5: GetProducts

        // GET: odata/Products
        public IHttpActionResult GetProducts(ODataQueryOptions<Product> queryOptions)
        {
            // validate the query.
            try
            {
                queryOptions.Validate(_validationSettings);
            }
            catch (ODataException ex)
            {
                return BadRequest(ex.Message);
            }

            // return Ok<IEnumerable<Product>>(products);
            return StatusCode(HttpStatusCode.NotImplemented);
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:16,代码来源:ProductsController.cs

示例6: GetPlayers

        public IHttpActionResult GetPlayers(ODataQueryOptions<Player> queryOptions)
        {
            // validate the query.
            try
            {
                queryOptions.Validate(_validationSettings);
            }
            catch (ODataException ex)
            {
                return BadRequest(ex.Message);
            }

            var players = _cricketContext.Players;
            return Ok<IEnumerable<Player>>(players);
        }
开发者ID:kevinrjones,项目名称:edft,代码行数:15,代码来源:PlayersController.cs

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

示例8: GetPlayer

        public IHttpActionResult GetPlayer([FromODataUri] int key, ODataQueryOptions<Player> queryOptions)
        {
            // validate the query.
            try
            {
                queryOptions.Validate(_validationSettings);
            }
            catch (ODataException ex)
            {
                return BadRequest(ex.Message);
            }

            var player = (from p in _cricketContext.Players
                          where p.Id == key
                          select p).First();
            return Ok(player);

        }
开发者ID:kevinrjones,项目名称:edft,代码行数:18,代码来源:PlayersController.cs

示例9: GetEmployees

        // GET: odata/Employees
        public async Task<IHttpActionResult> GetEmployees(ODataQueryOptions<Employee> queryOptions)
        {
            IEnumerable<Employee> ret = null;
            // validate the query.
            try
            {
                queryOptions.Validate(_validationSettings);
                var data = new NortWindModel();
                ret  =    data.Employees.ToList();
            }
            catch (ODataException ex)
            {
                return BadRequest(ex.Message);
            }

             return Ok<IEnumerable<Employee>>(ret);
            //return StatusCode(HttpStatusCode.NotImplemented);
        }
开发者ID:debapamdas,项目名称:GenericEntityFramework,代码行数:19,代码来源:EmployeesController.cs

示例10: GetEmployee

        // GET: odata/Employees(5)
        public async Task<IHttpActionResult> GetEmployee([FromODataUri] int key, ODataQueryOptions<Employee> queryOptions)
        {
            Employee ret = null;
            // validate the query.
            try
            {
                queryOptions.Validate(_validationSettings);
                var dbContext = new NortWindModel();
                ret = dbContext.Employees.FirstOrDefault(x => x.EmployeeID == key);

            }
            catch (ODataException ex)
            {
                return BadRequest(ex.Message);
            }

             return Ok<Employee>(ret);
            //return StatusCode(HttpStatusCode.NotImplemented);
        }
开发者ID:debapamdas,项目名称:GenericEntityFramework,代码行数:20,代码来源:EmployeesController.cs

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

示例12: GetTournaments

        public async Task<IHttpActionResult> GetTournaments(ODataQueryOptions<Tournament> queryOptions)
        {
            // validate the query.
            try
            {
                queryOptions.Validate(_validationSettings);
            }
            catch (ODataException ex)
            {
                return BadRequest(ex.Message);
            }

            DebReg.Models.User user = await GetUser();

            if (user == null)
            {
                return Unauthorized();
            }

            var tournaments = tournamentManager.GetTournaments().ToList();
            var result = tournaments.Select(t => new Tournament(t, user)).AsQueryable();
            return Ok(result);
        }
开发者ID:Rokory,项目名称:DebReg,代码行数:23,代码来源:TournamentsController.cs

示例13: ApplyQueryOptions

        private IQueryable ApplyQueryOptions(
            IQueryable queryable, ODataPath path, bool applyCount, out bool isIfNoneMatch, out ETag etag)
        {
            // ETAG IsIfNoneMatch is changed to public access, this flag can be removed.
            isIfNoneMatch = false;
            etag = null;

            if (this.shouldWriteRawValue)
            {
                // Query options don't apply to $value.
                return queryable;
            }

            HttpRequestMessageProperties properties = this.Request.ODataProperties();
            var model = Api.GetModelAsync().Result;
            ODataQueryContext queryContext =
                new ODataQueryContext(model, queryable.ElementType, path);
            ODataQueryOptions queryOptions = new ODataQueryOptions(queryContext, this.Request);

            // Get etag for query request
            if (queryOptions.IfMatch != null)
            {
                etag = queryOptions.IfMatch;
            }
            else if (queryOptions.IfNoneMatch != null)
            {
                isIfNoneMatch = true;
                etag = queryOptions.IfNoneMatch;
            }

            // TODO GitHubIssue#41 : Ensure stable ordering for query
            ODataQuerySettings settings = Api.Context.GetApiService<ODataQuerySettings>();

            if (this.shouldReturnCount)
            {
                // Query options other than $filter and $search don't apply to $count.
                queryable = queryOptions.ApplyTo(
                    queryable, settings, AllowedQueryOptions.All ^ AllowedQueryOptions.Filter);
                return queryable;
            }

            if (queryOptions.Count != null && !applyCount)
            {
                RestierQueryExecutorOptions queryExecutorOptions =
                    Api.Context.GetApiService<RestierQueryExecutorOptions>();
                queryExecutorOptions.IncludeTotalCount = queryOptions.Count.Value;
                queryExecutorOptions.SetTotalCount = value => properties.TotalCount = value;
            }

            // Validate query before apply, and query setting like MaxExpansionDepth can be customized here
            ODataValidationSettings validationSettings = Api.Context.GetApiService<ODataValidationSettings>();
            queryOptions.Validate(validationSettings);

            // Entity count can NOT be evaluated at this point of time because the source
            // expression is just a placeholder to be replaced by the expression sourcer.
            if (!applyCount)
            {
                queryable = queryOptions.ApplyTo(queryable, settings, AllowedQueryOptions.Count);
            }
            else
            {
                queryable = queryOptions.ApplyTo(queryable, settings);
            }

            return queryable;
        }
开发者ID:chinadragon0515,项目名称:RESTier,代码行数:66,代码来源:RestierController.cs

示例14: ValidateQuery

        public virtual void ValidateQuery(HttpRequestMessage request, ODataQueryOptions queryOptions)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            if (queryOptions == null)
            {
                throw Error.ArgumentNull("queryOptions");
            }

            IEnumerable<KeyValuePair<string, string>> queryParameters = request.GetQueryNameValuePairs();
            foreach (KeyValuePair<string, string> kvp in queryParameters)
            {
                if (!ODataQueryOptions.IsSystemQueryOption(kvp.Key) &&
                     kvp.Key.StartsWith("$", StringComparison.Ordinal))
                {
                    // we don't support any custom query options that start with $
                    throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.BadRequest,
                        Error.Format(SRResources.QueryParameterNotSupported, kvp.Key)));
                }
            }

            queryOptions.Validate(_validationSettings);
        }
开发者ID:modulexcite,项目名称:aspnetwebstack-1,代码行数:26,代码来源:EnableQueryAttribute.cs

示例15: CanTurnOffAllValidation

        public void CanTurnOffAllValidation()
        {
            // Arrange
            HttpRequestMessage message = new HttpRequestMessage(
                HttpMethod.Get,
                new Uri("http://localhost/?$filter=Name eq 'abc'")
            );

            ODataQueryContext context = ValidationTestHelper.CreateCustomerContext();
            ODataQueryOptions option = new ODataQueryOptions(context, message);
            ODataValidationSettings settings = new ODataValidationSettings()
            {
                AllowedQueryOptions = AllowedQueryOptions.OrderBy
            };

            // Act & Assert
            Assert.Throws<ODataException>(() => option.Validate(settings),
                "Query option 'Filter' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings.");

            option.Validator = null;
            Assert.DoesNotThrow(() => option.Validate(settings));

        }
开发者ID:shailendra9,项目名称:WebApi,代码行数:23,代码来源:ODataQueryOptionTest.cs


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