page_type | languages | products | description | urlFragment | ||
---|---|---|---|---|---|---|
sample |
|
|
Azure Cosmos DB is Microsoft's globally distributed multi-model database service |
azure-cosmos-db-cassandra-dotnet-core-getting-started |
Azure Cosmos DB is Microsoft's globally distributed multi-model database service. You can quickly create and query document, table, key-value, and graph databases, all of which benefit from the global distribution and horizontal scale capabilities at the core of Azure Cosmos DB.
This quick start demonstrates how to create an Azure Cosmos DB account for the Cassandra API by using the Azure portal. You'll then build a user profile console app, output as shown in the following image, with sample data.
Before you can run this sample, you must have the following pre-requisites:
- An active Azure Cassandra API Cosmos DB account - If you don't have an account, refer to Create Cassandra API account.
- Code editing: Microsoft Visual Studio or Microsoft Visual Studio Code (or another editor capable of editing C# files)
- The .NET Core SDK - this sample uses .NET Core 3.1. Download and install the SDK for your platform.
- Git client.
-
Clone this repository using
git clone https://github.com/Azure-Samples/azure-cosmos-db-cassandra-dotnet-core-getting-started.git
-
If you're using Visual Studio, open the CassandraQuickStartSample.sln solution. If you're using Visual Studio (VS) Code, open the folder containing the CassandraQuickStartSample.sln solution file in VS Code. Otherwise, use your preferred text or code editor.
-
Edit CassandraQuickStart/Program.cs. Substitute values for your Cosmos DB username, password, and contact endpoint for the "<PROVIDE>" placeholders at the top of the class definition. You can get these values from the Azure portal on your Cosmos DB account's "Connection String" blade.
-
If you're using Visual Studio: you can either install the Cassandra .NET driver using the Package Manager Console window, using the following command, or simply right-click the project node and select "Rebuild", which will restore missing Nuget packages including the Cassandra .NET driver.
PM> Install-Package CassandraCSharpDriver
-
If you're using VS Code: under the "Debug" menu, you can use "Start Debugging" (F5) or "Run without Debugging" (Ctrl-F5) to restore, build, and run the application.
-
Otherwise you can use the dotnet command line. At a prompt, navigate to the /CassandraQuickStart folder (this folder contains the CassandraQuickStart.csproj file) and type the following command.
dotnet run
You should see output similar to the following in your console or prompt:
The code included in this sample is intended to get you quickly started with a C# application using Cassandra C# driver that connects to Azure Cosmos DB with the Cassandra API.
Note that the CassandraCSharpDriver package used in this QuickStart is compatible with recent versions of .NET Framework and .NET Standard also. For details, see the package's Nuget page or project repository.