You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[!INCLUDE[Console app language selector](includes/tutorial-console-app-selector.md)]
22
21
23
-
The Azure SDK for .NET allows you to add data to an API for NoSQL container either [asynchronous individual operations](how-to-dotnet-create-item.md#create-an-item-asynchronously) or a [transactional batch](transactional-batch.md?tabs=dotnet). This tutorial will walk through the process of create a new .NET console application that adds multiple items to a container.
22
+
The Azure SDK for .NET allows you to add data to an API for NoSQL container either [asynchronous individual operations](how-to-dotnet-create-item.md#create-an-item-asynchronously) or a [transactional batch](transactional-batch.md?tabs=dotnet). This tutorial walks through the process of create a new .NET console application that adds multiple items to a container.
24
23
25
24
In this tutorial, you learn how to:
26
25
@@ -39,20 +38,20 @@ In this tutorial, you learn how to:
39
38
- If you have an existing Azure subscription, [create a new account](how-to-create-account.md?tabs=azure-portal).
40
39
- No Azure subscription? You can [try Azure Cosmos DB free](../try-free.md) with no credit card required.
41
40
-[Visual Studio Code](https://code.visualstudio.com)
42
-
-[.NET 6 (LTS) or later](https://dotnet.microsoft.com/download/dotnet/6.0)
41
+
-[.NET 8 or later](https://dotnet.microsoft.com/download/dotnet/8.0)
43
42
- Experience writing C# applications.
44
43
45
44
## Create API for NoSQL resources
46
45
47
-
First, create an empty database in the existing API for NoSQL account. You'll create a container using the Azure SDK for .NET later.
46
+
First, create an empty database in the existing API for NoSQL account. You create a container using the Azure SDK for .NET later.
48
47
49
48
1. Navigate to your existing API for NoSQL account in the [Azure portal](https://portal.azure.com/).
50
49
51
50
1. In the resource menu, select **Keys**.
52
51
53
52
:::image type="content" source="media/tutorial-dotnet-console-app/resource-menu-keys.png" lightbox="media/tutorial-dotnet-console-app/resource-menu-keys.png" alt-text="Screenshot of an API for NoSQL account page. The Keys option is highlighted in the resource menu.":::
54
53
55
-
1. On the **Keys** page, observe and record the value of the **URI** and **PRIMARY KEY** fields. These values will be used throughout the tutorial.
54
+
1. On the **Keys** page, observe and record the value of the **URI** and **PRIMARY KEY** fields. These values are used throughout the tutorial.
56
55
57
56
:::image type="content" source="media/tutorial-dotnet-console-app/page-keys.png" alt-text="Screenshot of the Keys page with the URI and Primary Key fields highlighted.":::
58
57
@@ -78,7 +77,7 @@ First, create an empty database in the existing API for NoSQL account. You'll cr
78
77
79
78
## Create .NET console application
80
79
81
-
Now, you'll create a new .NET console application and import the Azure SDK for .NET by using the `Microsoft.Azure.Cosmos` library from NuGet.
80
+
Now, you create a new .NET console application and import the Azure SDK for .NET by using the `Microsoft.Azure.Cosmos` library from NuGet.
82
81
83
82
1. Open a terminal in an empty directory.
84
83
@@ -156,7 +155,7 @@ Now, you'll create a new .NET console application and import the Azure SDK for .
156
155
157
156
## Add items to a container using the SDK
158
157
159
-
Next, you'll use individual operations to add items into the API for NoSQL container. In this section, you'll define the `CosmosHandler.ManageCustomerAsync` method.
158
+
Next, you use individual operations to add items into the API for NoSQL container. In this section, you define the `CosmosHandler.ManageCustomerAsync` method.
160
159
161
160
1. Create a new **CosmosHandler.cs** file.
162
161
@@ -174,7 +173,7 @@ Next, you'll use individual operations to add items into the API for NoSQL conta
174
173
{ }
175
174
```
176
175
177
-
1. Just to validate this app will work, create a short implementation of the static `ManageCustomerAsync` method to print the command-line input.
176
+
1. Just to validate this app works, create a short implementation of the static `ManageCustomerAsync` method to print the command-line input.
1. This time, the program should crash. If you scroll through the error message, you'll see the crash occurred because of a conflict in the unique identifier for the items.
335
+
1. This time, the program should crash. If you scroll through the error message, you see the crash occurred because of a conflict in the unique identifier for the items.
337
336
338
337
```output
339
338
Unhandled exception: Microsoft.Azure.Cosmos.CosmosException : Response status code does not indicate success: Conflict (409);Reason: (
@@ -371,12 +370,12 @@ Now that you've created your first item in the container, you can use the same S
371
370
1. Create a new string named `sql` with a SQL query to retrieve items where a filter (`@id`) matches.
372
371
373
372
```csharp
374
-
string sql = """
373
+
string sql = @"
375
374
SELECT
376
375
*
377
376
FROM customers c
378
377
WHERE c.id = @id
379
-
""";
378
+
";
380
379
```
381
380
382
381
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 of the variable `id` to the `@id` parameter.
@@ -413,10 +412,10 @@ Now that you've created your first item in the container, you can use the same S
413
412
1. Back in the terminal, run the application to read the single item using a SQL query.
1. The output of the command should indicate that the query required multiple RUs.
418
+
1. The output of the command should indicate that the query required multiple request units (RUs).
420
419
421
420
```output
422
421
[OK] mica-pereira 2.82 RUs
@@ -475,7 +474,7 @@ Now that you've created your first item in the container, you can use the same S
475
474
476
475
## Create a transaction using the SDK
477
476
478
-
Finally, you'll take the item you created, read that item, and create a different related item as part of a single transaction using the Azure SDK for .NET.
477
+
Finally, you take the item you created, read that item, and create a different related item as part of a single transaction using the Azure SDK for .NET.
479
478
480
479
1. Return to or open the **CosmosHandler.cs** file.
481
480
@@ -492,7 +491,7 @@ Finally, you'll take the item you created, read that item, and create a differen
492
491
493
492
1. For the next steps, add this new code within the `ManageCustomerAsync` method.
494
493
495
-
1. Create a new anonymous typed item using the `name`, `state`, and `country` method parameters and the `id` variable. Store the item as a variable named `customerCart`. This item will represent a real-time shopping cart for the customer that is currently empty.
494
+
1. Create a new anonymous typed item using the `name`, `state`, and `country` method parameters and the `id` variable. Store the item as a variable named `customerCart`. This item represents a real-time shopping cart for the customer that is currently empty.
496
495
497
496
```csharp
498
497
var customerCart = new {
@@ -506,7 +505,7 @@ Finally, you'll take the item you created, read that item, and create a differen
506
505
};
507
506
```
508
507
509
-
1. Create another new anonymous typed item using the `name`, `state`, and `country` method parameters and the `id` variable. Store the item as a variable named `customerCart`. This item will represent shipping and contact information for the customer.
508
+
1. Create another new anonymous typed item using the `name`, `state`, and `country` method parameters and the `id` variable. Store the item as a variable named `customerCart`. This item represents shipping and contact information for the customer.
510
509
511
510
```csharp
512
511
var customerContactInfo = new {
@@ -567,7 +566,7 @@ Finally, you'll take the item you created, read that item, and create a differen
567
566
568
567
## Validate the final data in the Data Explorer
569
568
570
-
To wrap up things, you'll use the Data Explorer in the Azure portal to view the data, and container you created in this tutorial.
569
+
To wrap up things, you use the Data Explorer in the Azure portal to view the data, and container you created in this tutorial.
571
570
572
571
1. Navigate to your existing API for NoSQL account in the [Azure portal](https://portal.azure.com/).
573
572
@@ -577,7 +576,7 @@ To wrap up things, you'll use the Data Explorer in the Azure portal to view the
577
576
578
577
1. On the **Data Explorer** page, expand the `cosmicworks` database, and then select the `customers` container.
579
578
580
-
:::image type="content" source="media/tutorial-dotnet-web-app/section-data-container.png" alt-text="Screenshot of the selected container node within the database node.":::
579
+
:::image type="content" source="media/tutorial-dotnet-console-app/data-explorer-container.png" alt-text="Screenshot of the selected container node within the database node.":::
581
580
582
581
1. In the command bar, select **New SQL query**.
583
582
@@ -591,7 +590,7 @@ To wrap up things, you'll use the Data Explorer in the Azure portal to view the
591
590
592
591
1. Select **Execute Query** to run the query and observe the results.
593
592
594
-
:::image type="content" source="media/tutorial-dotnet-console-app/page-data-explorer-execute-query.png" alt-text="Screenshot of the Execute Query option in the Data Explorer command bar.":::
593
+
:::image type="content" source="media/tutorial-dotnet-console-app/page-data-explorer-execute-query.png" alt-text="Screenshot of the 'Execute Query' option in the Data Explorer command bar.":::
595
594
596
595
1. The results should include a JSON array with three items created in this tutorial. Observe that all of the items have the same hierarchical partition key value, but unique ID fields. The example output included is truncated for brevity.
0 commit comments