如何在Asp.Net Core API中更改Microsoft.AspNetCore.OData ODataQueryOptions OData-Microsoft.AspNetCore.OData 版本=7.0.1.20718
我正在使用Asp.NETCore2.1WebAPI和OData。 如何更改Asp.Net Core API中的Microsoft.AspNetCore.OData ODataQueryOptions如何在Asp.Net Core API中更改Microsoft.AspNetCore.OData ODataQueryOptions OData-Microsoft.AspNetCore.OData 版本=7.0.1.20718,odata,asp.net-core-webapi,Odata,Asp.net Core Webapi,我正在使用Asp.NETCore2.1WebAPI和OData。 如何更改Asp.Net Core API中的Microsoft.AspNetCore.OData ODataQueryOptions public IQueryable<Product> Get( ODataQueryOptions<Product> options ) { //Alter QueryOptions Here } publicIQueryable获取(
public IQueryable<Product> Get( ODataQueryOptions<Product> options )
{
//Alter QueryOptions Here
}
publicIQueryable获取(ODataQueryOptions选项)
{
//在这里更改查询选项
}
我在.Net Framework中也做了同样的事情,但在Asp.Net Core 2.1中没有做同样的事情
public ODataQueryOptions<Product> CreateNewQueryOptions(string httpUrlWithODataQueryOptions)
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Products");
var edmModel = builder.GetEdmModel();
var config = new HttpConfiguration();
config.EnableDependencyInjection();
var req = new HttpRequestMessage(HttpMethod.Get, httpUrlWithODataQueryOptions);
req.SetConfiguration(config);
var queryOptions = new ODataQueryOptions<Product>(new ODataQueryContext(edmModel, typeof(Product), req.ODataProperties().Path), req);
return queryOptions;
}
公共ODataQueryOptions CreateNewQueryOptions(字符串httpUrlWithODataQueryOptions)
{
ODataConventionModelBuilder=新ODataConventionModelBuilder();
建筑商实体集(“产品”);
var edmModel=builder.GetEdmModel();
var config=新的HttpConfiguration();
config.EnableDependencyInjection();
var req=新的HttpRequestMessage(HttpMethod.Get,HttpUrlWithOdatQueryOptions);
请求设置配置(配置);
var queryOptions=新的ODataQueryOptions(新的ODataQueryContext(edmModel,typeof(Product),req.ODataProperties().Path),req);
返回查询选项;
}
我已经经历了以下几点: