我有一个ASP.NET 5应用程序,我想使用它的OData v4.
这是我试过的:
我导入以下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);
最后这是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)); }
现在,OData的调用正在由MVC的路由配置进行处理(很可能是因为我没有正确地使用ASP.NET 5注册OData).
有人可以帮我吗
解决方法
这是我们如何配置它与
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(); } } }
这是您可以自己尝试的方式.你将需要有@L_502_1@
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的结果