簡體   English   中英

OData控制器未返回實體

[英]OData controller not returning entities

當前,我正在使用ASP.NET Zero實現OData 我已按照文檔中的說明進行操作 ,但始終收到空響應。

這是我的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":[]}

可能是數據過濾器問題。

  1. 將日志記錄添加到數據庫上下文並檢查查詢。

      // In the constructor Database.Log = (s) => System.Diagnostics.Debug.WriteLine(s); 
  2. 檢查可能為您的數據過濾器設置參數的用戶范圍和自定義攔截器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM