|
1 | 1 | ---
|
2 |
| -title: Build an Azure Cosmos DB .NET Framework, Core application using the Gremlin API |
3 |
| -description: Presents a .NET Framework/Core code sample you can use to connect to and query Azure Cosmos DB |
| 2 | +title: 'Quickstart: Library for .NET' |
| 3 | +titleSuffix: Azure Cosmos DB for Apache Gremlin |
| 4 | +description: In this quickstart, connect to Azure Cosmos DB for Apache Gremlin using .NET. Then, create and traverse vertices and edges. |
4 | 5 | author: manishmsfte
|
5 | 6 | ms.author: mansha
|
| 7 | +ms.reviewer: sidandrews |
6 | 8 | ms.service: cosmos-db
|
7 | 9 | ms.subservice: apache-gremlin
|
8 |
| -ms.devlang: csharp |
9 | 10 | ms.topic: quickstart
|
10 |
| -ms.date: 05/02/2020 |
11 |
| -ms.custom: devx-track-dotnet, mode-api, ignite-2022 |
| 11 | +ms.date: 09/27/2023 |
| 12 | +# CustomerIntent: As a .NET developer, I want to use a library for my programming language so that I can create and traverse vertices and edges in code. |
12 | 13 | ---
|
13 |
| -# Quickstart: Build a .NET Framework or Core application using the Azure Cosmos DB for Gremlin account |
14 |
| -[!INCLUDE[Gremlin](../includes/appliesto-gremlin.md)] |
15 |
| - |
16 |
| -> [!div class="op_single_selector"] |
17 |
| -> * [Gremlin console](quickstart-console.md) |
18 |
| -> * [.NET](quickstart-dotnet.md) |
19 |
| -> * [Java](quickstart-java.md) |
20 |
| -> * [Node.js](quickstart-nodejs.md) |
21 |
| -> * [Python](quickstart-python.md) |
22 |
| -> * [PHP](quickstart-php.md) |
23 |
| -> |
24 |
| -
|
25 |
| -Azure Cosmos DB is Microsoft's globally distributed multi-model database service. You can quickly create and query document, key/value, and graph databases. All of which benefit from the global distribution and horizontal scale capabilities at the core of Azure Cosmos DB. |
26 |
| - |
27 |
| -This quickstart demonstrates how to create an Azure Cosmos DB [Gremlin API](introduction.md) account, database, and graph (container) using the Azure portal. You then build and run a console app built using the open-source driver [Gremlin.Net](https://tinkerpop.apache.org/docs/3.2.7/reference/#gremlin-DotNet). |
28 |
| - |
29 |
| -## Prerequisites |
30 |
| - |
31 |
| -Latest [!INCLUDE [cosmos-db-visual-studio](../includes/cosmos-db-visual-studio.md)] |
32 |
| - |
33 |
| -[!INCLUDE [quickstarts-free-trial-note](../../../includes/quickstarts-free-trial-note.md)] |
34 |
| - |
35 |
| -## Create a database account |
36 |
| - |
37 |
| -[!INCLUDE [cosmos-db-create-dbaccount-graph](../includes/cosmos-db-create-dbaccount-graph.md)] |
38 |
| - |
39 |
| -## Add a graph |
40 |
| - |
41 |
| -[!INCLUDE [cosmos-db-create-graph](../includes/cosmos-db-create-graph.md)] |
42 |
| - |
43 |
| -## Clone the sample application |
44 |
| - |
45 |
| -Now let's clone a Gremlin API app from GitHub, set the connection string, and run it. You'll see how easy it's to work with data programmatically. |
46 |
| - |
47 |
| -1. Open a command prompt, create a new folder named git-samples, then close the command prompt. |
48 |
| - |
49 |
| - ```bash |
50 |
| - md "C:\git-samples" |
51 |
| - ``` |
52 |
| - |
53 |
| -2. Open a git terminal window, such as git bash, and use the `cd` command to change to the new folder to install the sample app. |
54 |
| - |
55 |
| - ```bash |
56 |
| - cd "C:\git-samples" |
57 |
| - ``` |
58 |
| - |
59 |
| -3. Run the following command to clone the sample repository. The ``git clone`` command creates a copy of the sample app on your computer. |
60 |
| - |
61 |
| - ```bash |
62 |
| - git clone https://github.com/Azure-Samples/azure-cosmos-db-graph-gremlindotnet-getting-started.git |
63 |
| - ``` |
64 |
| - |
65 |
| -4. Then open Visual Studio and open the solution file. |
66 |
| - |
67 |
| -5. Restore the NuGet packages in the project. The restore operation should include the Gremlin.Net driver, and the Newtonsoft.Json package. |
68 |
| - |
69 |
| -6. You can also install the [email protected] driver manually using the NuGet package manager, or the [NuGet command-line utility](/nuget/install-nuget-client-tools): |
70 |
| - |
71 |
| - ```bash |
72 |
| - nuget install Gremlin.NET -Version 3.4.13 |
73 |
| - ``` |
74 |
| - |
75 |
| -> [!NOTE] |
76 |
| -> The supported Gremlin.NET driver version for Gremlin API is available [here](support.md#compatible-client-libraries). Latest released versions of Gremlin.NET may see incompatibilities, so please check the linked table for compatibility updates. |
77 |
| - |
78 |
| -## Review the code |
79 |
| - |
80 |
| -This step is optional. If you're interested in learning how the database resources are created in the code, you can review the following snippets. Otherwise, you can skip ahead to [Update your connection string](#update-your-connection-string). |
81 |
| -
|
82 |
| -The following snippets are all taken from the Program.cs file. |
83 | 14 |
|
84 |
| -* Set your connection parameters based on the account created above: |
| 15 | +# Quickstart: Azure Cosmos DB for Apache Gremlin library for Python |
85 | 16 |
|
86 |
| - :::code language="csharp" source="~/azure-cosmosdb-graph-dotnet/GremlinNetSample/Program.cs" id="configureConnectivity"::: |
87 |
| -
|
88 |
| -* The Gremlin commands to be executed are listed in a Dictionary: |
89 |
| -
|
90 |
| - :::code language="csharp" source="~/azure-cosmosdb-graph-dotnet/GremlinNetSample/Program.cs" id="defineQueries"::: |
91 |
| -
|
92 |
| -* Create a new `GremlinServer` and `GremlinClient` connection objects using the parameters provided above: |
93 |
| -
|
94 |
| - :::code language="csharp" source="~/azure-cosmosdb-graph-dotnet/GremlinNetSample/Program.cs" id="defineClientandServerObjects"::: |
95 |
| -
|
96 |
| -* Execute each Gremlin query using the `GremlinClient` object with an async task. You can read the Gremlin queries from the dictionary defined in the previous step and execute them. Later get the result and read the values, which are formatted as a dictionary, using the `JsonSerializer` class from Newtonsoft.Json package: |
97 |
| -
|
98 |
| - :::code language="csharp" source="~/azure-cosmosdb-graph-dotnet/GremlinNetSample/Program.cs" id="executeQueries"::: |
99 |
| -
|
100 |
| -## Update your connection string |
101 |
| -
|
102 |
| -Now go back to the Azure portal to get your connection string information and copy it into the app. |
103 |
| -
|
104 |
| -1. From the [Azure portal](https://portal.azure.com/), navigate to your graph database account. In the **Overview** tab, you can see two endpoints- |
105 |
| - |
106 |
| - **.NET SDK URI** - This value is used when you connect to the graph account by using Microsoft.Azure.Graphs library. |
107 |
| -
|
108 |
| - **Gremlin Endpoint** - This value is used when you connect to the graph account by using Gremlin.Net library. |
109 |
| -
|
110 |
| - :::image type="content" source="./media/quickstart-dotnet/endpoint.png" alt-text="Copy the endpoint"::: |
111 |
| -
|
112 |
| - For this sample, record the *Host* value of the **Gremlin Endpoint**. For example, if the URI is ``https://graphtest.gremlin.cosmosdb.azure.com``, the *Host* value would be ``graphtest.gremlin.cosmosdb.azure.com``. |
113 |
| -
|
114 |
| -1. Next, navigate to the **Keys** tab and record the *PRIMARY KEY* value from the Azure portal. |
115 |
| -
|
116 |
| -1. After you've copied the URI and PRIMARY KEY of your account, save them to a new environment variable on the local machine running the application. To set the environment variable, open a command prompt window, and run the following command. Make sure to replace ``<cosmos-account-name>`` and ``<cosmos-account-primary-key>`` values. |
117 |
| - |
118 |
| - ### [Windows](#tab/windows) |
119 |
| - |
120 |
| - ```powershell |
121 |
| - setx Host "<cosmos-account-name>.gremlin.cosmosdb.azure.com" |
122 |
| - setx PrimaryKey "<cosmos-account-primary-key>" |
123 |
| - ``` |
124 |
| - |
125 |
| - ### [Linux / macOS](#tab/linux+macos) |
126 |
| - |
127 |
| - ```bash |
128 |
| - export Host=<cosmos-account-name>.gremlin.cosmosdb.azure.com |
129 |
| - export PrimaryKey=<cosmos-account-primary-key> |
130 |
| - ``` |
131 |
| - |
132 |
| - --- |
133 |
| - |
134 |
| -1. Open the *Program.cs* file and update the "database and "container" variables with the database and container (which is also the graph name) names created above. |
135 |
| -
|
136 |
| - `private static string database = "your-database-name";` |
137 |
| - `private static string container = "your-container-or-graph-name";` |
138 |
| -
|
139 |
| -1. Save the Program.cs file. |
140 |
| -
|
141 |
| -You've now updated your app with all the info it needs to communicate with Azure Cosmos DB. |
142 |
| -
|
143 |
| -## Run the console app |
144 |
| -
|
145 |
| -Select CTRL + F5 to run the application. The application will print both the Gremlin query commands and results in the console. |
146 |
| -
|
147 |
| - The console window displays the vertexes and edges being added to the graph. When the script completes, press ENTER to close the console window. |
148 |
| -
|
149 |
| -## Browse using the Data Explorer |
150 |
| -
|
151 |
| -You can now go back to Data Explorer in the Azure portal and browse and query your new graph data. |
| 17 | +[!INCLUDE[Gremlin](../includes/appliesto-gremlin.md)] |
152 | 18 |
|
153 |
| -1. In Data Explorer, the new database appears in the Graphs pane. Expand the database and container nodes, and then select **Graph**. |
| 19 | +[!INCLUDE[Gremlin devlang](includes/quickstart-devlang.md)] |
154 | 20 |
|
155 |
| -2. Select the **Apply Filter** button to use the default query to view all the vertices in the graph. The data generated by the sample app is displayed in the Graphs pane. |
| 21 | +Azure Cosmos DB for Apache Gremlin is a fully managed graph database service implementing the popular [`Apache Tinkerpop`](https://tinkerpop.apache.org/), a graph computing framework using the Gremlin query language. The API for Gremlin gives you a low-friction way to get started using Gremlin with a service that can grow and scale out as much as you need with minimal management. |
156 | 22 |
|
157 |
| - You can zoom in and out of the graph, you can expand the graph display space, add extra vertices, and move vertices on the display surface. |
| 23 | +In this quickstart, you use the `Gremlin.Net` library to connect to a newly created Azure Cosmos DB for Gremlin account. |
158 | 24 |
|
159 |
| - :::image type="content" source="./media/quickstart-dotnet/graph-explorer.png" alt-text="View the graph in Data Explorer in the Azure portal"::: |
| 25 | +[Library source code](https://github.com/apache/tinkerpop/tree/master/gremlin-dotnet) | [Package (NuGet)](https://www.nuget.org/packages/Gremlin.Net) |
160 | 26 |
|
161 |
| -## Review SLAs in the Azure portal |
| 27 | +## Prerequisites |
162 | 28 |
|
163 |
| -[!INCLUDE [cosmosdb-tutorial-review-slas](../includes/cosmos-db-tutorial-review-slas.md)] |
| 29 | +- An Azure account with an active subscription. |
| 30 | + - No Azure subscription? [Sign up for a free Azure account](https://azure.microsoft.com/free/). |
| 31 | + - Don't want an Azure subscription? You can [try Azure Cosmos DB free](../try-free.md) with no subscription required. |
| 32 | +- [.NET (LTS)](https://dotnet.microsoft.com/) |
| 33 | + - Don't have .NET installed? Try this quickstart in a devcontainer. [](https://codespaces.new/github/codespaces-blank?quickstart=1) |
| 34 | +- [Azure Command-Line Interface (CLI)](/cli/azure/) |
164 | 35 |
|
165 |
| -## Clean up resources |
| 36 | +[!INCLUDE[Cloud Shell](../../../includes/cloud-shell-try-it.md)] |
166 | 37 |
|
167 |
| -[!INCLUDE [cosmosdb-delete-resource-group](../includes/cosmos-db-delete-resource-group.md)] |
| 38 | +## Create an API for Gremlin account and relevant resources |
168 | 39 |
|
169 |
| -## Next steps |
| 40 | +The API for Gremlin account should be created prior to using the .NET library. Additionally, it helps to also have the database and graph in place. |
170 | 41 |
|
171 |
| -In this quickstart, you've learned how to create an Azure Cosmos DB account, create a graph using the Data Explorer, and run an app. You can now build more complex queries and implement powerful graph traversal logic using Gremlin. |
| 42 | +[!INCLUDE[Create account, database, and graph](includes/create-account-database-graph-cli.md)] |
172 | 43 |
|
173 |
| -> [!div class="nextstepaction"] |
174 |
| -> [Query using Gremlin](tutorial-query.md) |
| 44 | +## |
0 commit comments