如何在支持OData查询的端点中解析ODataQuery ODataQueryOptions。

问题描述 投票:0回答:1

我使用net core 3.1., 我的项目包含api控制器(ODataController),支持OData查询的端点,我想解析OData查询,以便创建一个自定义请求来传递一些其他的休息服务。

一些支持OData查询的端点。

[HttpGet]
[EnableQuery]
public IEnumerable<WeatherForecast> Get()

[HttpGet]
[ODataRoute]
[EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False, MaxTop = 100, 
AllowedQueryOptions = AllowedQueryOptions.Select |AllowedQueryOptions.Count)]
public IEnumerable<WeatherForecast> Getlist(ODataQueryOptions options)
asp.net-core .net-core asp.net-core-mvc odata asp.net-core-webapi
1个回答
0
投票

我想你可以直接把它分解成它的构成部分。

ApplyClause applyClause = options.Apply.ApplyClause;
bool count = options.Count.Value;
FilterClause filterClause = options.Filter.FilterClause;
OrderByClause orderByClause = options.OrderBy.OrderByClause;
int skip = options.Skip.Value;
int top = options.Top.Value;
⋮

或者得到 string 版本。

string applyClause = options.RawValues.Apply;
string count = options.RawValues.Count;
string filterClause = options.RawValues.Filter;
string orderByClause = options.RawValues.OrderBy;
string skip = options.RawValues.Skip;
string top = options.RawValues.Top;
⋮
© www.soinside.com 2019 - 2024. All rights reserved.