YesSql.Provider.CosmosDb
0.1.2
dotnet add package YesSql.Provider.CosmosDb --version 0.1.2
NuGet\Install-Package YesSql.Provider.CosmosDb -Version 0.1.2
<PackageReference Include="YesSql.Provider.CosmosDb" Version="0.1.2" />
<PackageVersion Include="YesSql.Provider.CosmosDb" Version="0.1.2" />
<PackageReference Include="YesSql.Provider.CosmosDb" />
paket add YesSql.Provider.CosmosDb --version 0.1.2
#r "nuget: YesSql.Provider.CosmosDb, 0.1.2"
#:package YesSql.Provider.CosmosDb@0.1.2
#addin nuget:?package=YesSql.Provider.CosmosDb&version=0.1.2
#tool nuget:?package=YesSql.Provider.CosmosDb&version=0.1.2
YesSql.Provider.CosmosDb
An Azure Cosmos DB (NoSQL API) storage provider for YesSql — the document-database layer used by Orchard Core.
Status: Orchard Core boots and runs on this provider (validated — see
docs/ORCHARD-INTEGRATION.mdandsamples/OrchardSmokeTest), and YesSql's own conformance suite passes in full (249/249, 100%) — verified on both thePerTableandPerStorepartition strategies against the Cosmos emulator. Document CRUD, map + reduce indexes (full lifecycle), single- and multi-index queries (incl. raw LEFT/RIGHT joins), ordering, paging, counts,IN-subqueries, SQL date/decimal functions, DDL, optimistic concurrency (version + ETag), and unit-of-work rollback (atomic inPerStore, best-effort inPerTable) all work end-to-end. The only structural limit is true cross-partition ACID, which Cosmos does not offer (PerStore makes a unit of work single-partition so its rollback is atomic). Seedocs/CONFORMANCE.mdfor the matrix,docs/CROSS-PARTITION-ACID.mdfor the partitioning/ACID model, anddocs/ORCHARD-INTEGRATION.mdfor the Orchard wiring.
Why
YesSql ships first-party providers for SQL Server, PostgreSQL, MySQL, and SQLite only — all relational. This project closes the loop so YesSql (and therefore Orchard Core and any YesSql-based domain store) can run on Cosmos DB, enabling a single-Cosmos deployment topology.
Approach
This is a standalone NuGet package that depends on YesSql — not a fork. YesSql persists
through an ADO.NET DbConnection (from IConnectionFactory) driven by SQL from ISqlDialect, so the
provider supplies a co-designed pair:
- a Cosmos-backed ADO.NET shim (
DbConnection/DbCommand/DbDataReader/DbTransaction), and - an
ISqlDialectthat emits a constrained SQL surface the shim translates into Cosmos SDK operations.
Documents and index rows live as type-discriminated items in a single container, partitioned by their
source table name. See docs/ARCHITECTURE.md.
Usage
using YesSql;
using YesSql.Provider.CosmosDb;
using Microsoft.Azure.Cosmos;
var configuration = new Configuration()
.UseCosmosDb(new CosmosDbOptions
{
AccountEndpoint = "https://my-account.documents.azure.com:443/",
AccountKey = "<key>",
DatabaseId = "myapp",
ContainerId = "yessql", // default
PartitionKeyPath = "/pk", // default
// ClientOptions = ... // only needed for the emulator (see below)
})
.UseDefaultIdGenerator();
var store = await StoreFactory.CreateAndInitializeAsync(configuration);
await using var session = store.CreateSession();
await session.SaveAsync(new Person { Name = "Alice" });
await session.SaveChangesAsync();
Local emulator
The provider is developed against the Azure Cosmos DB Linux emulator (vnext preview). Two gotchas:
- The vnext emulator gateway serves HTTP on
:8081, not HTTPS — usehttp://localhost:8081/. - Use
ConnectionMode.Gateway+LimitToEndpoint = true, and accept the self-signed cert.
docker run -d --name cosmos-emu -p 8081:8081 -p 10250-10255:10250-10255 \
mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview
ClientOptions = new CosmosClientOptions
{
ConnectionMode = ConnectionMode.Gateway,
LimitToEndpoint = true,
HttpClientFactory = () => new HttpClient(new HttpClientHandler
{
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator,
}),
}
Building and testing
dotnet build YesSql.Provider.CosmosDb.slnx
# Hand-written provider tests (need the emulator running)
dotnet test test/YesSql.Provider.CosmosDb.Tests
# YesSql's own conformance suite against Cosmos (see docs/CONFORMANCE.md)
dotnet test test/Conformance/YesSql.Provider.CosmosDb.Conformance.csproj
Targets
net8.0;net10.0 — matching YesSql 5.4.7.
Continuous integration
A ready-to-use GitHub Actions workflow (build + Cosmos emulator + tests + pack) lives at
docs/github-actions-ci.yml. To enable it, copy it to
.github/workflows/ci.yml and push (adding a workflow file requires a token with the workflow scope).
License
MIT — see LICENSE.
| 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Azure.Cosmos (>= 3.60.0)
- Newtonsoft.Json (>= 13.0.4)
- YesSql (>= 5.4.7)
-
net8.0
- Microsoft.Azure.Cosmos (>= 3.60.0)
- Newtonsoft.Json (>= 13.0.4)
- YesSql (>= 5.4.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
0.1.2: fix paging regression — a bare OFFSET (.Skip without .Take) was dropped because Cosmos rejects OFFSET without LIMIT and the client-side fallback had been removed; now pairs a lone offset with a sentinel max LIMIT. Restores the full conformance suite to 249/249 (100%) on both PerTable and PerStore. 0.1.1: real-Azure-Cosmos correctness/scalability fixes found running a full Orchard Core setup against the classic (non-Postgres) emulator — (1) share a singleton CosmosClient per account instead of one per connection; (2) push OFFSET/LIMIT into Cosmos queries instead of trimming client-side; (3) provision database/container once per process, not on every connection open (control-plane ops are rate-limited on real Cosmos). 0.1.0: initial preview — ~92% of YesSql's conformance suite; Orchard Core boots and runs on Cosmos; PerTable and PerStore modes.