Possible to post ODataQueryOptions from the Http Request body?

后端 未结 3 2115
盖世英雄少女心
盖世英雄少女心 2021-02-15 16:44

I\'m implementing a Web API interface to support some fairly complex queries to run against it and have run up against an issue with the maximum request URI length.

Th

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-15 17:02

    You can pass the raw string value of the query options in the post body, and construct a query option in the post method of the controller.

    The code below is just for filter query option. You can add other query options the same way.

    public IQueryable Post([FromBody] string filterRawValue)
    {
        var context = new ODataQueryContext(Request.ODataProperties().Model, typeof(Report));
        var filterQueryOption = new FilterQueryOption(filterRawValue, context);
        var query = DbContext.Query();
        return (filterQueryOption.ApplyTo(query) as IQueryable).WithTranslations().Project(MappingEngine).To().WithTranslations();
    }
    

提交回复
热议问题