Skip to content

Commit fac233b

Browse files
authored
Merge pull request #271587 from seesharprun/patch-1
Cosmos DB | Update tutorial-dotnet-web-app.md
2 parents 1abf980 + 0d18e6e commit fac233b

File tree

2 files changed

+66
-54
lines changed

2 files changed

+66
-54
lines changed
-4.66 KB
Loading

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

Lines changed: 66 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.reviewer: esarroyo
99
ms.service: cosmos-db
1010
ms.subservice: nosql
1111
ms.topic: tutorial
12-
ms.date: 12/02/2022
12+
ms.date: 04/09/2024
1313
ms.devlang: csharp
1414
ms.custom: devx-track-dotnet, cosmos-dev-refresh, cosmos-dev-dotnet-path
1515
---
@@ -50,7 +50,7 @@ First, you'll create a database and container in the existing API for NoSQL acco
5050

5151
:::image type="content" source="media/tutorial-dotnet-web-app/resource-menu-keys.png" lightbox="media/tutorial-dotnet-web-app/resource-menu-keys.png" alt-text="Screenshot of an API for NoSQL account page. The Keys option is highlighted in the resource menu.":::
5252

53-
1. On the **Keys** page, observe and record the value of the **URI**, **PRIMARY KEY**, and **PRIMARY CONNECTION STRING*** fields. These values will be used throughout the tutorial.
53+
1. On the **Keys** page, observe and record the value of the **PRIMARY CONNECTION STRING*** field. This value will be used throughout the tutorial.
5454

5555
:::image type="content" source="media/tutorial-dotnet-web-app/page-keys.png" alt-text="Screenshot of the Keys page with the URI, Primary Key, and Primary Connection String fields highlighted.":::
5656

@@ -68,14 +68,14 @@ First, you'll create a database and container in the existing API for NoSQL acco
6868
| --- | --- |
6969
| **Database id** | `cosmicworks` |
7070
| **Database throughput type** | **Manual** |
71-
| **Database throughput amount** | `4000` |
71+
| **Database throughput amount** | `1000` |
7272
| **Container id** | `products` |
73-
| **Partition key** | `/categoryId` |
73+
| **Partition key** | `/category/name` |
7474

7575
:::image type="content" source="media/tutorial-dotnet-web-app/dialog-new-container.png" alt-text="Screenshot of the New Container dialog in the Data Explorer with various values in each field.":::
7676

7777
> [!IMPORTANT]
78-
> In this tutorial, we will first scale the database up to 4,000 RU/s in shared throughput to maximize performance for the data migration. Once the data migration is complete, we will scale down to 400 RU/s of provisioned throughput.
78+
> In this tutorial, we will first scale the database up to 1,000 RU/s in shared throughput to maximize performance for the data migration. Once the data migration is complete, we will scale down to 400 RU/s of provisioned throughput.
7979
8080
1. Select **OK** to create the database and container.
8181

@@ -84,36 +84,41 @@ First, you'll create a database and container in the existing API for NoSQL acco
8484
> [!TIP]
8585
> You can optionally use the Azure Cloud Shell here.
8686
87-
1. Install a **pre-release**version of the `cosmicworks` dotnet tool from NuGet.
87+
1. Install **v2** of the `cosmicworks` dotnet tool from NuGet.
8888

8989
```bash
90-
dotnet tool install --global cosmicworks --prerelease
90+
dotnet tool install --global cosmicworks --version 2.*
9191
```
9292

9393
1. Use the `cosmicworks` tool to populate your API for NoSQL account with sample product data using the **URI** and **PRIMARY KEY** values you recorded earlier in this lab. Those recorded values will be used for the `endpoint` and `key` parameters respectively.
9494

9595
```bash
9696
cosmicworks \
97-
--datasets product \
98-
--endpoint <uri> \
99-
--key <primary-key>
97+
--number-of-products 1759 \
98+
--number-of-employees 0 \
99+
--disable-hierarchical-partition-keys \
100+
--connection-string <nosql-connection-string>
100101
```
101102

102-
1. Observe the output from the command line tool. It should add more than 200 items to the container. The example output included is truncated for brevity.
103+
1. Observe the output from the command line tool. It should add 1759 items to the container. The example output included is truncated for brevity.
103104

104105
```output
106+
── Parsing connection string ────────────────────────────────────────────────────────────────
107+
╭─Connection string──────────────────────────────────────────────────────────────────────────╮
108+
│ AccountEndpoint=https://<account-name>.documents.azure.com:443/;AccountKey=<account-key>;
109+
╰────────────────────────────────────────────────────────────────────────────────────────────╯
110+
── Populating data ──────────────────────────────────────────────────────────────────────────
111+
╭─Products configuration─────────────────────────────────────────────────────────────────────╮
112+
│ Database cosmicworks │
113+
│ Container products │
114+
│ Count 1,759 │
115+
╰────────────────────────────────────────────────────────────────────────────────────────────╯
105116
...
106-
Revision: v4
107-
Datasets:
108-
product
109-
110-
Database: [cosmicworks] Status: Created
111-
Container: [products] Status: Ready
112-
113-
product Items Count: 295
114-
Entity: [9363838B-2D13-48E8-986D-C9625BE5AB26] Container:products Status: RanToCompletion
115-
...
116-
Container: [product] Status: Populated
117+
[SEED] 00000000-0000-0000-0000-000000005951 | Road-650 Black, 60 - Bikes
118+
[SEED] 00000000-0000-0000-0000-000000005950 | Mountain-100 Silver, 42 - Bikes
119+
[SEED] 00000000-0000-0000-0000-000000005949 | Men's Bib-Shorts, L - Clothing
120+
[SEED] 00000000-0000-0000-0000-000000005948 | ML Mountain Front Wheel - Components
121+
[SEED] 00000000-0000-0000-0000-000000005947 | Mountain-500 Silver, 42 - Bikes
117122
```
118123
119124
1. Return to the **Data Explorer** page for your account.
@@ -122,7 +127,7 @@ First, you'll create a database and container in the existing API for NoSQL acco
122127
123128
:::image type="content" source="media/tutorial-dotnet-web-app/section-data-database-scale.png" alt-text="Screenshot of the Scale option within the database node.":::
124129
125-
1. Reduce the throughput from **4,000** down to **400**.
130+
1. Reduce the throughput from **1,000** down to **400**.
126131
127132
:::image type="content" source="media/tutorial-dotnet-web-app/section-scale-throughput.png" alt-text="Screenshot of the throughput settings for the database reduced down to 400 RU/s.":::
128133
@@ -173,29 +178,33 @@ First, you'll create a database and container in the existing API for NoSQL acco
173178
174179
```sql
175180
SELECT
176-
p.name,
177-
p.categoryName,
178-
p.tags
181+
p.name,
182+
p.category.name AS category,
183+
p.category.subCategory.name AS subcategory,
184+
p.tags
179185
FROM products p
180-
JOIN t IN p.tags
181-
WHERE t.name = "Tag-32"
186+
JOIN tag IN p.tags
187+
WHERE STRINGEQUALS(tag, "yellow", true)
182188
```
183189
184190
1. The results should be a smaller array of items filtered to only contain items that include at least one tag with a **name** value of `Tag-32`. Again, a subset of the output is included here for brevity.
185191
186192
```output
187-
...
188-
{
189-
"name": "ML Mountain Frame - Black, 44",
190-
"categoryName": "Components, Mountain Frames",
191-
"tags": [
192-
{
193-
"id": "18AC309F-F81C-4234-A752-5DDD2BEAEE83",
194-
"name": "Tag-32"
195-
}
193+
[
194+
...
195+
{
196+
"name": "HL Touring Frame - Yellow, 60",
197+
"category": "Components",
198+
"subcategory": "Touring Frames",
199+
"tags": [
200+
"Components",
201+
"Touring Frames",
202+
"Yellow",
203+
"60"
204+
]
205+
},
206+
...
196207
]
197-
},
198-
...
199208
```
200209
201210
## Create ASP.NET web application
@@ -263,9 +272,9 @@ Now, you'll create a new ASP.NET web application using a sample project template
263272
264273
return new List<Product>()
265274
{
266-
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),
267-
...
268-
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+
...
269278
};
270279
}
271280
```
@@ -277,20 +286,25 @@ Now, you'll create a new ASP.NET web application using a sample project template
277286
{ }
278287
```
279288
280-
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.
281290
282291
```csharp
283292
public record Product(
284293
string id,
285-
string categoryId,
286-
string categoryName,
294+
Category category,
287295
string sku,
288296
string name,
289297
string description,
290298
decimal price
291299
);
292300
```
293301
302+
```csharp
303+
public record Category(
304+
string name
305+
);
306+
```
307+
294308
## Query data using the .NET SDK
295309
296310
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.
@@ -429,26 +443,24 @@ Next, you'll add the Azure SDK for .NET to this sample project and use the libra
429443
string sql = """
430444
SELECT
431445
p.id,
432-
p.categoryId,
433-
p.categoryName,
434-
p.sku,
435446
p.name,
447+
p.category,
448+
p.sku,
436449
p.description,
437-
p.price,
438-
p.tags
450+
p.price
439451
FROM products p
440-
JOIN t IN p.tags
441-
WHERE t.name = @tagFilter
452+
JOIN tag IN p.tags
453+
WHERE STRINGEQUALS(tag, @tagFilter, true)
442454
""";
443455
```
444456
445-
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.
446458
447459
```csharp
448460
var query = new QueryDefinition(
449461
query: sql
450462
)
451-
.WithParameter("@tagFilter", "Tag-75");
463+
.WithParameter("@tagFilter", "red");
452464
```
453465
454466
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)