From ba11c78ef9ad3c6862953a9bf8f792c9c52e74c3 Mon Sep 17 00:00:00 2001 From: Cesar De la Torre Date: Sat, 4 Mar 2017 17:29:36 -0800 Subject: [PATCH] Refactoring Catalog.API controllers and EF config --- .../Catalog.API/Controllers/CatalogController.cs | 12 ++++++------ src/Services/Catalog/Catalog.API/Startup.cs | 9 ++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs index 0d8ccc88a..547cdfe21 100644 --- a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs +++ b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs @@ -24,10 +24,10 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers ((DbContext)context).ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; } - // GET api/v1/[controller]/items/[?pageSize=3&pageIndex=10] + // GET api/v1/[controller]/items[?pageSize=3&pageIndex=10] [HttpGet] [Route("[action]")] - public async Task Items(int pageSize = 10, int pageIndex = 0) + public async Task Items([FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0) { var totalItems = await _context.CatalogItems .LongCountAsync(); @@ -46,10 +46,10 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers return Ok(model); } - // GET api/v1/[controller]/items/withname/samplename + // GET api/v1/[controller]/items/withname/samplename[?pageSize=3&pageIndex=10] [HttpGet] [Route("[action]/withname/{name:minlength(1)}")] - public async Task Items(string name, int pageSize = 10, int pageIndex = 0) + public async Task Items(string name, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0) { var totalItems = await _context.CatalogItems @@ -70,10 +70,10 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers return Ok(model); } - // GET api/v1/[controller]/items/type/1/brand/null + // GET api/v1/[controller]/items/type/1/brand/null[?pageSize=3&pageIndex=10] [HttpGet] [Route("[action]/type/{catalogTypeId}/brand/{catalogBrandId}")] - public async Task Items(int? catalogTypeId, int? catalogBrandId, int pageSize = 10, int pageIndex = 0) + public async Task Items(int? catalogTypeId, int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0) { var root = (IQueryable)_context.CatalogItems; diff --git a/src/Services/Catalog/Catalog.API/Startup.cs b/src/Services/Catalog/Catalog.API/Startup.cs index 2b44d0183..fb6cc3907 100644 --- a/src/Services/Catalog/Catalog.API/Startup.cs +++ b/src/Services/Catalog/Catalog.API/Startup.cs @@ -42,11 +42,10 @@ services.AddDbContext(c => { c.UseSqlServer(Configuration["ConnectionString"]); - c.ConfigureWarnings(wb => - { - //By default, in this application, we don't want to have client evaluations - wb.Log(RelationalEventId.QueryClientEvaluationWarning); - }); + // Changing default behavior when client evaluation occurs to throw. + // Default in EF Core would be to log a warning when client evaluation is performed. + c.ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)); + //Check Client vs. Server evaluation: https://docs.microsoft.com/en-us/ef/core/querying/client-eval }); services.Configure(Configuration);