@@ -28,44 +28,18 @@ public Startup(IConfiguration configuration)
28
28
29
29
public void ConfigureServices ( IServiceCollection services )
30
30
{
31
- services . AddDbContext < ProductDbContext > ( options =>
32
- options . UseNpgsql ( Configuration . GetConnectionString ( "ProductConStr" ) ) ) ;
33
-
31
+ services . AddDbContext < ProductDbContext > (
32
+ options => options . UseNpgsql ( Configuration . GetConnectionString ( "ProductConStr" ) ) ) ;
34
33
services . AddScoped ( typeof ( IRepository < > ) , typeof ( Repository < > ) ) ;
35
34
36
- services . AddOData ( ) ;
37
- services . AddMvc ( options =>
38
- {
39
- options . EnableEndpointRouting = false ;
40
- // https://github.com/OData/WebApi/issues/1177
41
- foreach ( var outputFormatter in options . OutputFormatters . OfType < ODataOutputFormatter > ( )
42
- . Where ( _ => _ . SupportedMediaTypes . Count == 0 ) )
43
- {
44
- outputFormatter . SupportedMediaTypes . Add (
45
- new MediaTypeHeaderValue ( "application/prs.odatatestxx-odata" ) ) ;
46
- }
47
-
48
- foreach ( var inputFormatter in options . InputFormatters . OfType < ODataInputFormatter > ( )
49
- . Where ( _ => _ . SupportedMediaTypes . Count == 0 ) )
50
- {
51
- inputFormatter . SupportedMediaTypes . Add (
52
- new MediaTypeHeaderValue ( "application/prs.odatatestxx-odata" ) ) ;
53
- }
54
- } )
35
+ services
36
+ . AddMvc ( options => options . EnableEndpointRouting = false )
55
37
. SetCompatibilityVersion ( CompatibilityVersion . Version_2_2 ) ;
38
+ services . AddOData ( ) ;
56
39
}
57
40
58
41
public void Configure ( IApplicationBuilder app , IHostingEnvironment env )
59
42
{
60
- if ( env . IsDevelopment ( ) )
61
- {
62
- app . UseDeveloperExceptionPage ( ) ;
63
- }
64
- else
65
- {
66
- app . UseHsts ( ) ;
67
- }
68
-
69
43
using ( var serviceScope = app . ApplicationServices . GetRequiredService < IServiceScopeFactory > ( ) . CreateScope ( ) )
70
44
{
71
45
using ( var context = serviceScope . ServiceProvider . GetService < ProductDbContext > ( ) )
@@ -75,10 +49,12 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
75
49
}
76
50
77
51
app . UseMvc (
78
- rb =>
52
+ routeBuilder =>
79
53
{
80
- rb . MapODataServiceRoute ( "ODataRoute" , "odata" , GetEdmModel ( ) ) ;
81
- rb . EnableDependencyInjection ( ) ;
54
+ // Workaround: https://github.com/OData/WebApi/issues/1175
55
+ // routeBuilder.EnableDependencyInjection();
56
+ routeBuilder . Filter ( ) . Count ( ) . Expand ( ) . OrderBy ( ) . Select ( ) . MaxTop ( 1 ) ;
57
+ routeBuilder . MapODataServiceRoute ( "ODataRoute" , "odata" , GetEdmModel ( ) ) ;
82
58
} ) ;
83
59
}
84
60
@@ -87,12 +63,10 @@ private static IEdmModel GetEdmModel()
87
63
var builder = new ODataConventionModelBuilder ( ) ;
88
64
builder . EnableLowerCamelCase ( ) ;
89
65
90
- builder . EntitySet < Product > ( "products" )
91
- . EntityType . Filter ( ) . Count ( ) . Expand ( ) . OrderBy ( ) . Page ( ) . Select ( ) ;
92
-
93
- builder . EntitySet < ProductCategory > ( "product_categories" )
94
- . EntityType . Filter ( ) . Count ( ) . Expand ( ) . OrderBy ( ) . Page ( ) . Select ( ) ;
95
-
66
+ builder . EntitySet < Product > ( "products" ) ;
67
+ // .EntityType.Filter().Count().Expand().OrderBy().Page().Select();
68
+ builder . EntitySet < ProductCategory > ( "product_categories" ) ;
69
+ // .EntityType.Filter().Count().Expand().OrderBy().Page().Select();
96
70
return builder . GetEdmModel ( ) ;
97
71
}
98
72
}
0 commit comments