Skip to content

Commit 0a5b469

Browse files
committed
Updating code snippet format
1 parent 5ede6af commit 0a5b469

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

articles/cosmos-db/create-sql-api-dotnet-v4.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,63 +145,64 @@ To learn in more about the hierarchy of different entities, see the [working wit
145145

146146
The sample code described in this article creates a family database in Azure Cosmos DB. The family database contains family details such as name, address, location, the associated parents, children, and pets. Before populating the data to your Azure Cosmos account, define the properties of a family item. Create a new class named `Family.cs` at the root level of your sample application and add the following code to it:
147147

148-
:::code language="csharp" source="~/cosmos-dotnet-v4-getting-started/src/Family.cs":::
148+
[!code-csharp[Main](~/cosmos-dotnet-v4-getting-started/src/Family.cs)]
149149

150150
### Add the using directives & define the client object
151151

152152
From the project directory, open the `Program.cs` file in your editor and add the following using directives at the top of your application:
153153

154-
:::code language="csharp" source="~/cosmos-dotnet-v4-getting-started/src/Program.cs" id="Usings":::
154+
[!code-csharp[Main](~/cosmos-dotnet-v4-getting-started/src/Program.cs?name=Usings)]
155+
155156

156157
Add the following global variables in your `Program` class. These will include the endpoint and authorization keys, the name of the database, and container that you will create. Make sure to replace the endpoint and authorization keys values according to your environment.
157158

158-
:::code language="csharp" source="~/cosmos-dotnet-v4-getting-started/src/Program.cs" id="Constants":::
159+
[!code-csharp[Main](~/cosmos-dotnet-v4-getting-started/src/Program.cs?name=Constants)]
159160

160161
Finally, replace the `Main` method:
161162

162-
:::code language="csharp" source="~/cosmos-dotnet-v4-getting-started/src/Program.cs" id="Main":::
163+
[!code-csharp[Main](~/cosmos-dotnet-v4-getting-started/src/Program.cs?name=Main)]
163164

164165
### Create a database
165166

166167
Define the `CreateDatabaseAsync` method within the `program.cs` class. This method creates the `FamilyDatabase` if it doesn't already exist.
167168

168-
:::code language="csharp" source="~/cosmos-dotnet-v4-getting-started/src/Program.cs?" id="CreateDatabaseAsync":::
169+
[!code-csharp[Main](~/cosmos-dotnet-v4-getting-started/src/Program.cs?name=CreateDatabaseAsync)]
169170

170171
### Create a container
171172

172173
Define the `CreateContainerAsync` method within the `Program` class. This method creates the `FamilyContainer` if it doesn't already exist.
173174

174-
:::code language="csharp" source="~/cosmos-dotnet-v4-getting-started/src/Program.cs" id="CreateContainerAsync":::
175+
[!code-csharp[Main](~/cosmos-dotnet-v4-getting-started/src/Program.cs?name=CreateContainerAsync)]
175176

176177
### Create an item
177178

178179
Create a family item by adding the `AddItemsToContainerAsync` method with the following code. You can use the `CreateItemAsync` or `UpsertItemAsync` methods to create an item:
179180

180-
:::code language="csharp" source="~/cosmos-dotnet-v4-getting-started/src/Program.cs" id="AddItemsToContainerAsync":::
181+
[!code-csharp[Main](~/cosmos-dotnet-v4-getting-started/src/Program.cs?name=AddItemsToContainerAsync)]
181182

182183
### Query the items
183184

184185
After inserting an item, you can run a query to get the details of "Andersen" family. The following code shows how to execute the query using the SQL query directly. The SQL query to get the "Anderson" family details is: `SELECT * FROM c WHERE c.LastName = 'Andersen'`. Define the `QueryItemsAsync` method within the `Program` class and add the following code to it:
185186

186-
:::code language="csharp" source="~/cosmos-dotnet-v4-getting-started/src/Program.cs" id="QueryItemsAsync":::
187+
[!code-csharp[Main](~/cosmos-dotnet-v4-getting-started/src/Program.cs?name=QueryItemsAsync)]
187188

188189
### Replace an item
189190

190191
Read a family item and then update it by adding the `ReplaceFamilyItemAsync` method with the following code.
191192

192-
:::code language="csharp" source="~/cosmos-dotnet-v4-getting-started/src/Program.cs" id="ReplaceFamilyItemAsync":::
193+
[!code-csharp[Main](~/cosmos-dotnet-v4-getting-started/src/Program.cs?name=ReplaceFamilyItemAsync)]
193194

194195
### Delete an item
195196

196197
Delete a family item by adding the `DeleteFamilyItemAsync` method with the following code.
197198

198-
:::code language="csharp" source="~/cosmos-dotnet-v4-getting-started/src/Program.cs" id="DeleteFamilyItemAsync":::
199+
[!code-csharp[Main](~/cosmos-dotnet-v4-getting-started/src/Program.cs?name=DeleteFamilyItemAsync)]
199200

200201
### Delete the database
201202

202203
Finally you can delete the database adding the `DeleteDatabaseAndCleanupAsync` method with the following code:
203204

204-
:::code language="csharp" source="~/cosmos-dotnet-v4-getting-started/src/Program.cs" id="DeleteDatabaseAndCleanupAsync":::
205+
[!code-csharp[Main](~/cosmos-dotnet-v4-getting-started/src/Program.cs?name=DeleteDatabaseAndCleanupAsync)]
205206

206207
After you add all the required methods, save the `Program` file.
207208

0 commit comments

Comments
 (0)