Skip to content

Commit 0d18e6e

Browse files
authored
Rework ASP.NET application
1 parent 059a264 commit 0d18e6e

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

articles/cosmos-db/nosql/tutorial-dotnet-web-app.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ Now, you'll create a new ASP.NET web application using a sample project template
272272
273273
return new List<Product>()
274274
{
275-
new Product(id: "baaa4d2d-5ebe-45fb-9a5c-d06876f408e0", categoryId: "3E4CEACD-D007-46EB-82D7-31F6141752B2", categoryName: "Components, Road Frames", sku: "FR-R72R-60", name: """ML Road Frame - Red, 60""", description: """The product called "ML Road Frame - Red, 60".""", price: 594.83000000000004m),
276-
...
277-
new Product(id: "d5928182-0307-4bf9-8624-316b9720c58c", categoryId: "AA5A82D4-914C-4132-8C08-E7B75DCE3428", categoryName: "Components, Cranksets", sku: "CS-6583", name: """ML Crankset""", description: """The product called "ML Crankset".""", price: 256.49000000000001m)
275+
new Product(id: "baaa4d2d-5ebe-45fb-9a5c-d06876f408e0", category: new Category(name: "Components, Road Frames"), sku: "FR-R72R-60", name: """ML Road Frame - Red, 60""", description: """The product called "ML Road Frame - Red, 60".""", price: 594.83000000000004m),
276+
new Product(id: "bd43543e-024c-4cda-a852-e29202310214", category: new Category(name: "Components, Forks"), sku: "FK-5136", name: """ML Fork""", description: """The product called "ML Fork".""", price: 175.49000000000001m),
277+
...
278278
};
279279
}
280280
```
@@ -286,20 +286,25 @@ Now, you'll create a new ASP.NET web application using a sample project template
286286
{ }
287287
```
288288
289-
1. Finally, navigate to and open the **Models/Product.cs** file. Observe the record type defined in this file. This type will be used in queries throughout this tutorial.
289+
1. Finally, navigate to and open the **Models/Product.cs** and **Models/Category.cs** files. Observe the record types defined in each file. These types will be used in queries throughout this tutorial.
290290
291291
```csharp
292292
public record Product(
293293
string id,
294-
string categoryId,
295-
string categoryName,
294+
Category category,
296295
string sku,
297296
string name,
298297
string description,
299298
decimal price
300299
);
301300
```
302301
302+
```csharp
303+
public record Category(
304+
string name
305+
);
306+
```
307+
303308
## Query data using the .NET SDK
304309
305310
Next, you'll add the Azure SDK for .NET to this sample project and use the library to query data from the API for NoSQL container.
@@ -438,26 +443,24 @@ Next, you'll add the Azure SDK for .NET to this sample project and use the libra
438443
string sql = """
439444
SELECT
440445
p.id,
441-
p.categoryId,
442-
p.categoryName,
443-
p.sku,
444446
p.name,
447+
p.category,
448+
p.sku,
445449
p.description,
446-
p.price,
447-
p.tags
450+
p.price
448451
FROM products p
449-
JOIN t IN p.tags
450-
WHERE t.name = @tagFilter
452+
JOIN tag IN p.tags
453+
WHERE STRINGEQUALS(tag, @tagFilter, true)
451454
""";
452455
```
453456
454-
1. Create a new `QueryDefinition` variable named `query` passing in the `sql` string as the only query parameter. Also, use the `WithParameter` fluid method to apply the value `Tag-75` to the `@tagFilter` parameter.
457+
1. Create a new `QueryDefinition` variable named `query` passing in the `sql` string as the only query parameter. Also, use the `WithParameter` fluid method to apply the value `red` to the `@tagFilter` parameter.
455458
456459
```csharp
457460
var query = new QueryDefinition(
458461
query: sql
459462
)
460-
.WithParameter("@tagFilter", "Tag-75");
463+
.WithParameter("@tagFilter", "red");
461464
```
462465
463466
1. Use the `GetItemQueryIterator<>` generic method and the `query` variable to create an iterator that gets data from Azure Cosmos DB. Store the iterator in a variable named `feed`. Wrap this entire expression in a using statement to dispose the iterator later.

0 commit comments

Comments
 (0)