我有一个API控制器,该控制器调用ODataController实例以获取数据。
据我了解,我可以通过实例化控制器,调用POST
方法,然后应用EnableQueryAttribute来实现。
Get()
ODataQueryOptions的构建因异常而失败
string ODataQuery = "/odata/entity?$filter=...&$top=1";
// Get the queryable
DataController dc = new DataController();
IQueryable queryable = dc.Get();
// Get the EdmModel
IEdmModel model = WebApiConfig.GetEdmModel();
// constructing requirements for OData query
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, reportRequest.DataUriDecoded);
ODataQueryContext ctx = new ODataQueryContext(model, typeof(Medizinprodukte), null);
requestMessage.Properties[HttpPropertyKeys.HttpConfigurationKey] = new HttpConfiguration();
ODataQueryOptions queryOptions = new ODataQueryOptions(ctx, requestMessage);
// Apply OData Query
EnableQueryAttribute enableQuery = new EnableQueryAttribute();
var result = enableQuery.ApplyQuery(queryable, queryOptions);
我想这可以追溯到我构建"No non-OData HTTP route registered."
的方式,将NULL作为ODataQueryContext
参数传入。
不幸的是,我找不到一种可行的方法来创建has been asked before, but resolved for older version OData only的ODataPath实例。
关于如何解决此问题的任何想法?