我正在開發一個使用Web Api和ODataController的OData查詢庫。當我從Web瀏覽器運行我的api時,它什麼都不返回。我沒有收到任何類型的錯誤。我可以在Visual Studio中進行調試,並清楚地看到該方法運行併成功將我的結果返回爲IQueryable <>。在引擎蓋下的某處它丟棄了我的數據。有沒有其他人看到或遇到過這個?我已經包括了我的代碼如下,僅供參考:Web Api OData控制器返回空白頁無錯誤
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.OData;
using Epm.Core.Model;
using System.Web.Http.OData.Query;
using Epm.Data.Access;
using Epm.Service.Assemblers;
namespace Epm.Service.Web.Controllers.OData
{
public class SearchActionsController : ODataController
{
private readonly EpmEntities context = new EpmEntities();
[Queryable(AllowedQueryOptions=AllowedQueryOptions.All)]
public IQueryable<ActionStepDisplay> Get(int planId, int? factorId, bool? showArchived)
{
var user = this.GetCurrentUser();
var results = (from p in context.SearchActions(user.SessionId, planId, factorId, showArchived, 1, null)
select p).ToModel().ToArray();
return results.AsQueryable();
}
protected override void Dispose(bool disposing)
{
context.Dispose();
base.Dispose(disposing);
}
}
}
我的配置:
ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<Epm.Core.Model.ActionStep>("SearchActions");
Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel();
config.Routes.MapODataRoute("ODataRoute", "odata", model);
嘗試運行在小提琴手查詢不接受(406),看看是否有響應的任何錯誤。 –