我正在开发一个使用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),看看是否有响应的任何错误。 –