Skip to content

Commit 708e5bf

Browse files
Fix $top in OData examples. Resolves #944
1 parent af3e31d commit 708e5bf

File tree

10 files changed

+30
-12
lines changed

10 files changed

+30
-12
lines changed

examples/AspNet/OData/OpenApiODataWebApiExample/Configuration/PersonModelConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public void Apply( ODataModelBuilder builder, ApiVersion apiVersion, string rout
1818

1919
person.HasKey( p => p.Id );
2020
person.Select().OrderBy( "firstName", "lastName" );
21+
person.Page( maxTopValue: 100, pageSizeValue: default );
2122

2223
if ( apiVersion < ApiVersions.V3 )
2324
{

examples/AspNet/OData/OpenApiODataWebApiExample/Configuration/ProductConfiguration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ public void Apply( ODataModelBuilder builder, ApiVersion apiVersion, string rout
1818
return;
1919
}
2020

21-
var product = builder.EntitySet<Product>( "Products" ).EntityType.HasKey( p => p.Id );
21+
var product = builder.EntitySet<Product>( "Products" ).EntityType;
2222

23+
product.HasKey( p => p.Id );
24+
product.Page( maxTopValue: 100, pageSizeValue: default );
2325
product.Action( "Rate" ).Parameter<int>( "stars" );
2426
product.Collection.Action( "Rate" ).Parameter<int>( "stars" );
2527
}

examples/AspNet/OData/OpenApiODataWebApiExample/Configuration/SupplierConfiguration.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public void Apply( ODataModelBuilder builder, ApiVersion apiVersion, string rout
1818
return;
1919
}
2020

21-
builder.EntitySet<Supplier>( "Suppliers" ).EntityType.HasKey( p => p.Id );
21+
var supplier = builder.EntitySet<Supplier>( "Suppliers" ).EntityType;
22+
23+
supplier.HasKey( p => p.Id );
24+
supplier.Page( maxTopValue: 100, pageSizeValue: default );
25+
2226
builder.Singleton<Supplier>( "Acme" );
2327
}
2428
}

examples/AspNet/OData/OpenApiODataWebApiExample/Models/Order.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/// <summary>
88
/// Represents an order.
99
/// </summary>
10+
[Page( MaxTop = 100 )]
1011
[Select]
1112
[Select( "effectiveDate", SelectType = SelectExpandType.Disabled )]
1213
public class Order

examples/AspNet/OData/OpenApiODataWebApiExample/V3/SuppliersController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public IHttpActionResult Put( [FromODataUri] int key, [FromBody] Supplier update
118118
/// </summary>
119119
/// <param name="key">The supplier identifier.</param>
120120
/// <returns>The associated supplier products.</returns>
121-
[EnableQuery]
121+
[EnableQuery( MaxTop = 100 )]
122122
public IQueryable<Product> GetProducts( [FromODataUri] int key ) =>
123123
suppliers.Where( s => s.Id == key ).SelectMany( s => s.Products );
124124

examples/AspNetCore/OData/ODataOpenApiExample/Configuration/PersonModelConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public void Apply( ODataModelBuilder builder, ApiVersion apiVersion, string rout
1818

1919
person.HasKey( p => p.Id );
2020
person.Select().OrderBy( "firstName", "lastName" );
21+
person.Page( maxTopValue: 100, pageSizeValue: default );
2122

2223
if ( apiVersion < ApiVersions.V3 )
2324
{

examples/AspNetCore/OData/ODataOpenApiExample/Configuration/ProductConfiguration.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public void Apply( ODataModelBuilder builder, ApiVersion apiVersion, string rout
1818
return;
1919
}
2020

21-
var product = builder.EntitySet<Product>( "Products" ).EntityType.HasKey( p => p.Id );
21+
var product = builder.EntitySet<Product>( "Products" ).EntityType;
22+
23+
product.HasKey( p => p.Id );
24+
product.Page( maxTopValue: 100, pageSizeValue: default );
2225
}
2326
}

examples/AspNetCore/OData/ODataOpenApiExample/Configuration/SupplierConfiguration.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ public void Apply( ODataModelBuilder builder, ApiVersion apiVersion, string rout
1818
return;
1919
}
2020

21-
builder.EntitySet<Supplier>( "Suppliers" ).EntityType.HasKey( p => p.Id );
21+
var supplier = builder.EntitySet<Supplier>( "Suppliers" ).EntityType;
22+
23+
24+
supplier.HasKey( p => p.Id );
25+
supplier.Page( maxTopValue: 100, pageSizeValue: default );
26+
2227
builder.Singleton<Supplier>( "Acme" );
2328
}
2429
}

examples/AspNetCore/OData/ODataOpenApiExample/Models/Order.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/// <summary>
77
/// Represents an order.
88
/// </summary>
9+
[Page( MaxTop = 100 )]
910
[Select]
1011
[Select( "effectiveDate", SelectType = SelectExpandType.Disabled )]
1112
public class Order

examples/AspNetCore/OData/ODataOpenApiExample/V3/SuppliersController.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
public class SuppliersController : ODataController
1818
{
1919
private readonly IQueryable<Supplier> suppliers = new[]
20-
{
21-
NewSupplier( 1 ),
22-
NewSupplier( 2 ),
20+
{
21+
NewSupplier( 1 ),
22+
NewSupplier( 2 ),
2323
NewSupplier( 3 ),
2424
}.AsQueryable();
2525

@@ -46,7 +46,7 @@ public class SuppliersController : ODataController
4646
[Produces( "application/json" )]
4747
[ProducesResponseType( typeof( Supplier ), Status200OK )]
4848
[ProducesResponseType( Status404NotFound )]
49-
public SingleResult<Supplier> Get( int key ) =>
49+
public SingleResult<Supplier> Get( int key ) =>
5050
SingleResult.Create( suppliers.Where( p => p.Id == key ) );
5151

5252
/// <summary>
@@ -147,7 +147,7 @@ public IActionResult Put( int key, [FromBody] Supplier update )
147147
/// <param name="key">The supplier identifier.</param>
148148
/// <returns>The associated supplier products.</returns>
149149
[HttpGet]
150-
[EnableQuery]
150+
[EnableQuery( MaxTop = 100 )]
151151
public IQueryable<Product> GetProducts( int key ) =>
152152
suppliers.Where( s => s.Id == key ).SelectMany( s => s.Products );
153153

@@ -181,8 +181,8 @@ public IActionResult CreateRef(
181181
[ProducesResponseType( Status204NoContent )]
182182
[ProducesResponseType( Status404NotFound )]
183183
public IActionResult DeleteRef(
184-
int key,
185-
int relatedKey,
184+
int key,
185+
int relatedKey,
186186
string navigationProperty ) => NoContent();
187187

188188
private static Supplier NewSupplier( int id ) =>

0 commit comments

Comments
 (0)