我正在使用Microsoft.AspNetCore.OData 7.0.0 nuget程序包。
我已经注册了我的OData路由前缀,如下所示。
app.UseMvc(routeBuilder =>
{
var builder = new ModelODataBuilder();
routeBuilder.EnableDependencyInjection();
routeBuilder.MapODataServiceRoute("ODataRoutes", "odata/Route1", builder.GetEdmModel(app.ApplicationServices));
});
每个OData控制器都有一个ODataRoutePrefix,其中前缀对应于在GetEdmModel中声明和配置的EntitySet。例如
[ODataRoutePrefix("Service1")]
但是,我需要某些服务的路由前缀为“ odata / Route1”,而其他服务的路由前缀为“ odata / Route2”。例如
http://odata/Route1/Service1 http://odata/Route2/Service2
我不知道如何配置它。以下代码不起作用
app.UseMvc(routeBuilder =>
{
var builder = new ModelODataBuilder();
routeBuilder.EnableDependencyInjection();
routeBuilder.MapODataServiceRoute("ODataRoute1", "odata/Route1", builder.GetEdmModelForRoute1(app.ApplicationServices));
routeBuilder.MapODataServiceRoute("ODataRoute2", "odata/Route1", builder.GetEdmModelForRoute2(app.ApplicationServices));
});
有人知道我将如何配置它吗?
答案 0 :(得分:0)
我想我找到了办法。
在Startup.cs中添加了一个额外的应用程序。UseMvc
app.UseMvc( b =>
{
b.Select( ).Expand( ).Filter( ).OrderBy( ).MaxTop( 100 ).Count( );
b.MapODataServiceRoute( "odata" , "odata" , EdmModelBuilder.GetEdmModel( app.ApplicationServices ) );
} );
app.UseMvc( b =>
{
b.Select( ).Expand( ).Filter( ).OrderBy( ).MaxTop( 100 ).Count( );
b.MapODataServiceRoute( "membership" , "membershipapi" , EdmModelBuilderMembership.GetEdmModel( app.ApplicationServices ) );
} );
到目前为止,它一直在工作...
您还必须更改代码,以免在两个映射中使用相同的路径:“ odata / Route1”