CosmosDbGenericRepository 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CosmosDbGenericRepository --version 1.0.0                
NuGet\Install-Package CosmosDbGenericRepository -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CosmosDbGenericRepository" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CosmosDbGenericRepository --version 1.0.0                
#r "nuget: CosmosDbGenericRepository, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CosmosDbGenericRepository as a Cake Addin
#addin nuget:?package=CosmosDbGenericRepository&version=1.0.0

// Install CosmosDbGenericRepository as a Cake Tool
#tool nuget:?package=CosmosDbGenericRepository&version=1.0.0                

Generic Repository for Cosmos DB

This repository contains a generic repository class for managing entities in Cosmos DB. The GenericRepository class provides basic CRUD operations (Create, Read, Update, Delete) for any type of entity.

Usage

To use the GenericRepository, you need to provide the type of the entity and the type of the entity's identifier when creating an instance of the class. The entity type should be a class.

Here's an example of how to create a GenericRepository for a Bug entity with a string identifier:

var cosmosClient = new CosmosClient("your-connection-string"); var repository = new GenericRepository<Bug, string>(cosmosClient);

Once you have an instance of the GenericRepository, you can use it to perform CRUD operations on Bug entities. Here's an example of how to add a new Bug to the repository:

var bug = new Bug { Id = "1", Name = "Fly", Age = 42 }; await repository.AddAsync(bug);

Methods

The GenericRepository provides the following methods:

  • AddAsync(T entity): Adds a new entity to the repository.
  • DeleteAsync(IDType id): Deletes an entity from the repository.
  • GetAllAsync(): Gets all entities from the repository.
  • GetByIdAsync(IDType id): Gets an entity by its identifier.
  • UpdateAsync(T entity, IDType id): Updates an entity in the repository.

Requirements

To use the GenericRepository, you need to have the Azure Cosmos DB SDK installed. You can install it via NuGet:

Install-Package Microsoft.Azure.Cosmos

You also need to provide a valid Cosmos DB connection string when creating the CosmosClient.

Contributing

Contributions are welcome. Please open an issue or submit a pull request on GitHub.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 204 12/11/2023
1.0.0 123 12/11/2023