我正在尝试第一次在控制器上实现Odata,并且遇到了该主题中的错误。我尝试了许多在这里和其他站点上发现的不同方法,但是我没有任何运气。
我声明了以下控制器。
using System.Web.Http;
using System.Collections.Generic;
using AutoMapper;
using Microsoft.AspNet.OData;
using System.Linq;
using Microsoft.AspNet.OData.Routing;
using Microsoft.AspNet.OData.Query;
namespace Site.API.Areas.Prices.Controllers
{
public class PricesController : ODataController
{
IPricesManager pricesManager;
public PricesController()
{
this.pricesManager = new PricesManager();
}
public IHttpActionResult GetPrice()
{
var result = this.PricesManager.RetrieveAll();
return Ok(result.AsQueryable());
}
}
}
以及我的WebApiConfig中的以下内容
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<PricesModel>("Prices").EntityType.HasKey(p => p.Facility);
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: null,
model: builder.GetEdmModel());
如果我要调用任何一种普通的API,我会使用:
https://localhost/API/Site.API/Prices/Prices
对于OData,我正在尝试
https://localhost/API/Site.API/odata/Prices
结果是出现主题错误。我想念什么?