【问题标题】:OData controller not returning entitiesOData 控制器不返回实体
【发布时间】: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


    【解决方案1】:

    可能是数据过滤器问题。

    1. 将日志记录添加到数据库上下文并检查查询。

        // In the constructor
        Database.Log = (s) => System.Diagnostics.Debug.WriteLine(s);
      
    2. 检查可能正在为您的数据过滤器设置参数的用户范围和自定义拦截器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-14
      • 2014-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-11
      相关资源
      最近更新 更多