我有一个ASP.NET 5应用程序,我想使用OData v4。
以下是我的尝试:
1.我导入了以下nuget包:
"Microsoft.AspNet.WebApi": "5.2.3",
"Microsoft.AspNet.OData": "5.7.0",
"Microsoft.AspNet.Hosting": "1.0.0-rc1-final"
2.在Startup.Configure
方法
GlobalConfiguration.Configure(ConfigOData);
3.最后这是OData配置
private static void ConfigOData(HttpConfiguration config)
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
var EDM = builder.GetEdmModel();
//OData v4.0
config.MapODataServiceRoute("odata", "odata", EDM,
new DefaultODataPathHandler(),
conventions,
new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
}
现在,MVC的路由配置正在处理OData调用(很可能是因为我没有正确地向ASP.NET 5注册OData)。
有人可以帮我这个吗?
答案 0 :(得分:6)
以下是我们如何使用ASP.NET Core RC2 OData.
配置它namespace ODataSample
{
using Microsoft.AspNetCore.OData.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using ODataSample.Models;
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddOData<ISampleService>();
}
public void Configure(IApplicationBuilder app)
{
app.UseOData("odata");
app.UseMvc();
}
}
}
以下是您自己尝试的方法。您需要the .NET Core SDK installed.
git clone git@github.com:bigfont/WebApi.git
cd WebApi\vNext\src\Microsoft.AspNetCore.OData
dotnet restore
cd ..\..\samples\ODataSample.BigFont\
dotnet restore
dotnet run
这是http://localhost:5000/odata
链接