Skip to content

Commit 860587f

Browse files
Merge pull request #277335 from seesharprun/patch-7
Cosmos DB | Fix typo in .NET console tutorial for NoSQL
2 parents f802c85 + 4e4f1e8 commit 860587f

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed
17.9 KB
Loading

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ title: |
33
Tutorial: Develop a .NET console application with Azure Cosmos DB for NoSQL
44
description: |
55
.NET tutorial to create a console application that adds data to Azure Cosmos DB for NoSQL.
6-
author: seesharprun
7-
ms.author: sidandrews
8-
ms.reviewer: esarroyo
6+
author: StefArroyo
7+
ms.author: esarroyo
98
ms.service: cosmos-db
109
ms.subservice: nosql
1110
ms.topic: tutorial
12-
ms.date: 11/02/2022
11+
ms.date: 06/05/2024
1312
ms.devlang: csharp
1413
ms.custom: devx-track-dotnet, cosmos-dev-refresh, cosmos-dev-dotnet-path
1514
---
@@ -20,7 +19,7 @@ ms.custom: devx-track-dotnet, cosmos-dev-refresh, cosmos-dev-dotnet-path
2019

2120
[!INCLUDE[Console app language selector](includes/tutorial-console-app-selector.md)]
2221

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.
2423

2524
In this tutorial, you learn how to:
2625

@@ -39,20 +38,20 @@ In this tutorial, you learn how to:
3938
- If you have an existing Azure subscription, [create a new account](how-to-create-account.md?tabs=azure-portal).
4039
- No Azure subscription? You can [try Azure Cosmos DB free](../try-free.md) with no credit card required.
4140
- [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)
4342
- Experience writing C# applications.
4443

4544
## Create API for NoSQL resources
4645

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.
4847

4948
1. Navigate to your existing API for NoSQL account in the [Azure portal](https://portal.azure.com/).
5049

5150
1. In the resource menu, select **Keys**.
5251

5352
:::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.":::
5453

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.
5655

5756
:::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.":::
5857

@@ -78,7 +77,7 @@ First, create an empty database in the existing API for NoSQL account. You'll cr
7877

7978
## Create .NET console application
8079

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.
8281

8382
1. Open a terminal in an empty directory.
8483

@@ -156,7 +155,7 @@ Now, you'll create a new .NET console application and import the Azure SDK for .
156155
157156
## Add items to a container using the SDK
158157
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.
160159
161160
1. Create a new **CosmosHandler.cs** file.
162161
@@ -174,7 +173,7 @@ Next, you'll use individual operations to add items into the API for NoSQL conta
174173
{ }
175174
```
176175
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.
178177
179178
```csharp
180179
public static async Task ManageCustomerAsync(string name, string email, string state, string country)
@@ -227,7 +226,7 @@ Next, you'll use individual operations to add items into the API for NoSQL conta
227226
1. Back within the static **CosmosHandler** class, create a new asynchronous method named `GetContainerAsync` that returns an `Container`.
228227
229228
```csharp
230-
private static async Task<Container> GetContainer()
229+
private static async Task<Container> GetContainerAsync()
231230
{ }
232231
```
233232
@@ -333,7 +332,7 @@ Next, you'll use individual operations to add items into the API for NoSQL conta
333332
dotnet run -- --name 'Mica Pereira' --state 'Washington' --country 'United States'
334333
```
335334
336-
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.
337336
338337
```output
339338
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
371370
1. Create a new string named `sql` with a SQL query to retrieve items where a filter (`@id`) matches.
372371
373372
```csharp
374-
string sql = """
373+
string sql = @"
375374
SELECT
376375
*
377376
FROM customers c
378377
WHERE c.id = @id
379-
""";
378+
";
380379
```
381380
382381
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
413412
1. Back in the terminal, run the application to read the single item using a SQL query.
414413
415414
```bash
416-
dotnet run -- --name 'Mica Pereira'
415+
dotnet run -- --name 'Mica Pereira' --state 'Washington' --country 'United States'
417416
```
418417
419-
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).
420419
421420
```output
422421
[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
475474
476475
## Create a transaction using the SDK
477476
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.
479478
480479
1. Return to or open the **CosmosHandler.cs** file.
481480
@@ -492,7 +491,7 @@ Finally, you'll take the item you created, read that item, and create a differen
492491
493492
1. For the next steps, add this new code within the `ManageCustomerAsync` method.
494493
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.
496495
497496
```csharp
498497
var customerCart = new {
@@ -506,7 +505,7 @@ Finally, you'll take the item you created, read that item, and create a differen
506505
};
507506
```
508507
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.
510509
511510
```csharp
512511
var customerContactInfo = new {
@@ -567,7 +566,7 @@ Finally, you'll take the item you created, read that item, and create a differen
567566
568567
## Validate the final data in the Data Explorer
569568
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.
571570
572571
1. Navigate to your existing API for NoSQL account in the [Azure portal](https://portal.azure.com/).
573572
@@ -577,7 +576,7 @@ To wrap up things, you'll use the Data Explorer in the Azure portal to view the
577576
578577
1. On the **Data Explorer** page, expand the `cosmicworks` database, and then select the `customers` container.
579578
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.":::
581580
582581
1. In the command bar, select **New SQL query**.
583582
@@ -591,7 +590,7 @@ To wrap up things, you'll use the Data Explorer in the Azure portal to view the
591590
592591
1. Select **Execute Query** to run the query and observe the results.
593592
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.":::
595594
596595
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.
597596

0 commit comments

Comments
 (0)