【发布时间】:2018-09-21 09:36:07
【问题描述】:
目前,我正在使用 ASP.NET 零实现 OData。我已经按照文档中的instructions 进行操作,但总是得到一个空响应。
这是我的 Web API 模块PreInitialize 代码:
public override void PreInitialize()
{
var builder = Configuration.Modules.AbpWebApiOData().ODataModelBuilder;
// Configure your entities here...
builder.EntitySet<Author>("Authors");
}
我为作者创建了一个 OData 控制器并覆盖了 Get 方法:
public class AuthorsController : AbpODataEntityController<Author, long>, ITransientDependency
{
private readonly IRepository<Author, long> _repository;
public AuthorsController(IRepository<Author, long> repository) : base(repository)
{
_repository = repository;
}
[EnableQuery]
[UnitOfWork(IsDisabled = true)]
public override IQueryable<Author> Get()
{
return _repository.GetAll();
}
[EnableQuery]
public override SingleResult<Author> Get([FromODataUri] long key)
{
return new SingleResult<Author>(_repository.GetAll().Where(x=>x.Id==key));
}
}
导航到 URL http://localhost:6235/odata/Authors 后,我在 OData 响应中只看到 value 的空数组:
{"@odata.context":"http://localhost:6235/odata/$metadata#Jobs","value":[]}
【问题讨论】:
标签: c# asp.net-mvc-5 odata aspnetboilerplate