CosmosDbGenericRepository 1.0.1
dotnet add package CosmosDbGenericRepository --version 1.0.1
NuGet\Install-Package CosmosDbGenericRepository -Version 1.0.1
<PackageReference Include="CosmosDbGenericRepository" Version="1.0.1" />
paket add CosmosDbGenericRepository --version 1.0.1
#r "nuget: CosmosDbGenericRepository, 1.0.1"
// Install CosmosDbGenericRepository as a Cake Addin #addin nuget:?package=CosmosDbGenericRepository&version=1.0.1 // Install CosmosDbGenericRepository as a Cake Tool #tool nuget:?package=CosmosDbGenericRepository&version=1.0.1
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,"database","container");
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 | Versions 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. |
-
net8.0
- Microsoft.Azure.Cosmos (>= 3.37.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.