我使用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)
我想你可以直接把它分解成它的构成部分。
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;
⋮