以编程方式创建ODataQueryOptions [英] Create an ODataQueryOptions programmatically
问题描述
我的API当前具有一些OData终结点,这些终结点使用通用的ODataQueryOptions来接收OData查询...
My API currently has some OData endpoints that use generic ODataQueryOptions to recieve an OData query...
[HttpGet]
[Route("search")]
public object Search(ODataQueryOptions<MySearchableEntity> options)
{
return searchService.Search(options);
}
然后,
searchService
遍历options.Filter.FilterClause
的Expression
以构建自定义SQL查询.它对order,top和skip参数执行类似的操作.
searchService
then traverses the Expression
of options.Filter.FilterClause
to build a custom SQL query. It does similar stuff for the order, top and skip parameters.
这一切都很好,但是我现在需要它来解析动态类型的查询.
This is all working fine, but I now need it to parse a query for a dynamic type.
是否可以以编程方式为ODataQueryContext构建EdmModel和IEdmType等,而无需备份真实" CLR类型?
Is it possible to programmatically build an EdmModel and IEdmType etc for the ODataQueryContext, without having a 'real' CLR type backing it up?
类型"的定义很明确,因为我们有描述其形状的类,但它不作为CLR类型存在.
The 'type' is well defined in that we have classes describing its shape, but it doesn't exist as a CLR type.
推荐答案
回答我自己的问题,因为我找到了答案.
Answering my own question, as I've found the answer.
用于验证查询的ODataQueryContext
接受Type
,但是有一个重载,它接受IEdmType,而IEdmType可以是EdmModel
,很容易构建成一堆不同的方式.
The ODataQueryContext
that is used to validate the query accepts a Type
, but there is an overload that accepts an IEdmType, which in turn can be an EdmModel
, which is very easy to build in a bunch of different ways.
此处的文档:
http://odata.github.io/WebApi/02-01-model-builder-abstract/
http://odata.github.io/WebApi/02-02-model-builder-untyped/
http://odata.github.io/WebApi/02-03-model-builder-nonconvention/
http://odata.github.io/WebApi/02-04-convention-model-builder/
这篇关于以编程方式创建ODataQueryOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!