【发布时间】:2017-11-03 21:18:16
【问题描述】:
我有一个常规控制器,它具有 odata 功能:
[Route("[controller]")]
public class ChannelsController : Controller
{
private readonly ChannelContext db = new ChannelContext();
public IQueryable<PrdChannel> Get()
{
var entities = db.PrdChannel.AsQueryable();
var modelManager = (IODataModelManger) HttpContext.RequestServices.GetService(typeof(IODataModelManger));
var model = modelManager.GetModel(nameof(ProductConfiguration));
var queryContext = new ODataQueryContext(model, typeof(PrdChannel), null);
var queryOptions = new ODataQueryOptions(queryContext, HttpContext.Request);
return queryOptions
.ApplyTo(entities, new ODataQuerySettings
{
HandleNullPropagation = HandleNullPropagationOption.True
})
.Cast<PrdChannel>();
}
}
我可以发出 GET:https://myservice/Channel?$filter=cable lt 10
但是,当我尝试执行$select 时,它不起作用!
https://myservice/Channel?$select=cable
根据OdataQueryOptions的定义,不支持选择/展开。
问题:我们如何在 aspnetcore 中支持 $select?
也许这应该是一个 ODataController?
【问题讨论】:
标签: c# .net asp.net-core visual-studio-2017 odata