Azure-Samples / cosmos-db-nosql-dotnet-samples

Sample .NET applications for Azure Cosmos DB for NoSQL

Home Page:https://learn.microsoft.com/azure/cosmos-db/nosql/quickstart-dotnet

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Azure Cosmos DB for NoSQL client library samples for .NET

Validate .NET code samples

Getting started

This repo has a devcontainer environment making it easy to get started.

Open in GitHub Codespaces

Run the app

Configure your Azure Cosmos DB credentials as environment variables.

export COSMOS_ENDPOINT="<cosmos-account-URI>"
export COSMOS_KEY="<cosmos-account-PRIMARY-KEY>"

đź’ˇ TIP: If you don't have an Azure Cosmos DB account, create a free account.

Run the quickstart sample app using the Microsoft.Azure.Cosmos package from NuGet.

cd 001-quickstart/
dotnet add package Microsoft.Azure.Cosmos
dotnet run

Validate any changes you make

If you change the code, run the formatter and test the build.

dotnet format

dotnet build

Troubleshooting certificate errors

If you use a self-signed certificate, you may need to disable the client's validation:

CosmosClientOptions options = new ()
{
    HttpClientFactory = () => new HttpClient(new HttpClientHandler()
    {
        ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
    }),
    ConnectionMode = ConnectionMode.Gateway
};
    >
using CosmosClient client = new(
  ...,
  ...,
  clientOptions: options
);

About

Sample .NET applications for Azure Cosmos DB for NoSQL

https://learn.microsoft.com/azure/cosmos-db/nosql/quickstart-dotnet

License:MIT License


Languages

Language:C# 100.0%