Skip to content

✨ Add Azure Cosmos DB provider (eQuantic.Core.Data.EntityFramework.CosmosDb) - #2

Merged
edgarmesquita merged 4 commits into
masterfrom
feature/cosmosdb-provider
Jul 20, 2026
Merged

edgarmesquita merged 4 commits into
masterfrom
feature/cosmosdb-provider

Conversation

@edgarmesquita

Copy link
Copy Markdown
Contributor

What

Adds a new non-relational EF Core provider — eQuantic.Core.Data.EntityFramework.CosmosDb — for
Azure Cosmos DB, mirroring the existing MongoDb provider and slotting into the v5 family (per-major
8.x/10.x packaging).

Design

Cosmos via EF Core is a document store, so the provider builds on the base (not Relational) and only
overrides the four bulk operations Cosmos can't do server-side (ExecuteDelete/ExecuteUpdate are
relational-only):

  • DeleteMany/DeleteManyAsync — load the matching documents, RemoveRange + SaveChanges; return
    the matched count.
  • UpdateMany/UpdateManyAsync — extract the assigned members from the x => new T { … } expression,
    load the matches, and apply only those members to each (each value evaluated against the loaded
    entity, so x.Count + 1 works). Unassigned fields are left intact.

Everything else (Find/Insert/Execute, the QueryOptions → IQueryable translation) is inherited from
SetBase.

Partition keys

A Cosmos-specific QueryOptions extension so a read targets one logical partition instead of a
cross-partition scan:

new QueryOptions<OrderData>()
    .WithPartitionKey(tenantId)
    .Where(o => o.Status, FilterOperator.Equal, OrderStatus.Paid);

WithPartitionKey(string) is available on both net8 and net10; the 2- and 3-level hierarchical overloads
are net10-only (EF Cosmos 8 has no hierarchical API).

Packaging

  • Per-major: 8.2.0 (net8, EF Cosmos 8.0.29) and 10.1.0 (net10, EF Cosmos 10.0.10) — same PackageId
    across lines, consistent with the family.
  • Base InternalsVisibleTo extended to the new assembly (the set reaches the base's internal DbSet).
  • Registered in the solution and the ci.yml/release.yml matrices (14 build / 4 test).

Tests (10, all green)

  • CosmosUpdateExpression setter extraction — constant + entity-referencing values; rejects
    non-member-init / null.
  • The four bulk ops via EF Core in-memory — including the guard that UpdateMany leaves unassigned
    members intact.
  • WithPartitionKey registers a before-customization and chains.

Integration against a real Cosmos DB (emulator) is out of scope here: the bulk-op logic is exercised
through the in-memory provider, and WithPartitionKey's Cosmos-only execution is covered at the wiring
level. A Testcontainers/emulator suite is the natural follow-up (same gap noted for the other providers).

New non-relational EF Core provider for Azure Cosmos DB, mirroring the MongoDb provider. The Set overrides the four bulk operations via load-then-modify through the DbContext (Cosmos has no ExecuteDelete/ExecuteUpdate); UpdateMany extracts the assigned members from the update expression and evaluates each value against the loaded entity (so x.Count + 1 works) and touches only those members. Adds a QueryOptions.WithPartitionKey extension (single string on net8/net10, plus 2- and 3-level hierarchical keys on net10). Per-major packages 8.2.0 (EF Cosmos 8.0.29) and 10.1.0 (EF Cosmos 10.0.10); base InternalsVisibleTo extended to the new assembly. Registered in the solution and the ci.yml/release.yml matrices (14 build / 4 test). 10 unit tests (setter extraction, the four bulk ops via EF in-memory, WithPartitionKey wiring).
Adds a Why (the motivation the core-data README leads with) and a self-contained Getting started (install → entity/context/unit-of-work → registration → first query), so a reader can wire the provider up without leaving the README; folds the old Install section in. Fixes the intro to list Azure Cosmos DB alongside the other providers. Repository.md §7 now notes that set-based DeleteMany/UpdateMany run as server-side statements only on the relational providers — MongoDB uses its native driver and Cosmos DB loads-then-modifies. Marks docs/IMPROVEMENT_PLAN.md as historical/completed so it is not mistaken for the current design.
…ameworkUnitOfWork

Now that the shared EntityFrameworkUnitOfWork lives in the base package, the Cosmos unit of work drops to overriding CreateSetCore only (removing the duplicated ~200-line copy that SonarCloud flagged). Bumps CosmosDb to 8.3.0/10.2.0 to line up with the base (4.6.0) it now depends on.
@sonarqubecloud

Copy link
Copy Markdown

@edgarmesquita
edgarmesquita merged commit bb6d2f5 into master Jul 20, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants