OData 控制器不返回实体
OData controller not returning entities
目前,我正在文档中实施 OData with ASP.NET Zero. I have followed the 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":[]}
可能是数据过滤器问题。
将日志记录添加到数据库上下文并检查查询。
// In the constructor
Database.Log = (s) => System.Diagnostics.Debug.WriteLine(s);
检查可能正在为您的数据过滤器设置参数的用户范围和自定义拦截器。
目前,我正在文档中实施 OData with ASP.NET Zero. I have followed the 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":[]}
可能是数据过滤器问题。
将日志记录添加到数据库上下文并检查查询。
// In the constructor Database.Log = (s) => System.Diagnostics.Debug.WriteLine(s);
检查可能正在为您的数据过滤器设置参数的用户范围和自定义拦截器。