diff --git a/samples/features/json/product-catalog/.gitignore b/samples/features/json/product-catalog/.gitignore index 46be2cf4..8b5804c3 100644 --- a/samples/features/json/product-catalog/.gitignore +++ b/samples/features/json/product-catalog/.gitignore @@ -1,5 +1,6 @@ *.xproj.user .vs/* +.vscode/* bin/* obj/* *.sln diff --git a/samples/features/json/product-catalog/Controllers/ProductController.cs b/samples/features/json/product-catalog/Controllers/ProductController.cs index e4589447..da373ffb 100644 --- a/samples/features/json/product-catalog/Controllers/ProductController.cs +++ b/samples/features/json/product-catalog/Controllers/ProductController.cs @@ -25,14 +25,22 @@ namespace ProductCatalog.Controllers [HttpGet] public async Task Get() { - await sqlQuery.Stream("select * from Product FOR JSON PATH, ROOT('data')", Response.Body, EMPTY_PRODUCTS_ARRAY); + await sqlQuery.Stream( +@"select ProductID, Name, Color, Price, Quantity, JSON_VALUE(Data, '$.MadeIn') as MadeIn, JSON_QUERY(Tags) as Tags +from Product +FOR JSON PATH, ROOT('data')", Response.Body, EMPTY_PRODUCTS_ARRAY); } // GET api/Product/5 [HttpGet("{id}")] public async Task Get(int id) { - var cmd = new SqlCommand("select * from Product where ProductId = @id FOR JSON PATH, WITHOUT_ARRAY_WRAPPER"); + var cmd = new SqlCommand( +@"select ProductID, Name, Color, Price, Quantity +from Product +where ProductId = @id +FOR JSON PATH, WITHOUT_ARRAY_WRAPPER"); + cmd.Parameters.AddWithValue("id", id); await sqlQuery.Stream(cmd, Response.Body, "{}"); } diff --git a/samples/features/json/product-catalog/sql-scripts/setup.sql b/samples/features/json/product-catalog/sql-scripts/setup.sql index 3b88b32e..ecf052c7 100644 --- a/samples/features/json/product-catalog/sql-scripts/setup.sql +++ b/samples/features/json/product-catalog/sql-scripts/setup.sql @@ -73,8 +73,8 @@ AS BEGIN Size = json.Size, Price = json.Price, Quantity = json.Quantity, - Data = json.Data, - Tags = json.Tags + Data = ISNULL(json.Data, Data), + Tags = ISNULL(json.Tags,Tags) FROM OPENJSON(@ProductJson) WITH ( Name nvarchar(100) N'strict $."Name"', Color nvarchar(30), diff --git a/samples/features/json/product-catalog/wwwroot/index.html b/samples/features/json/product-catalog/wwwroot/index.html index 2154f9ae..ab47f5c4 100644 --- a/samples/features/json/product-catalog/wwwroot/index.html +++ b/samples/features/json/product-catalog/wwwroot/index.html @@ -63,9 +63,10 @@