dotnet/efcore · error · NotSupportedException
The Cosmos database provider does not support transactions.
Error message
The Cosmos database provider does not support transactions.
What it means
The Cosmos DB provider does not support explicit transactions. Cosmos only provides implicit transactional batches scoped to a single partition; it has no multi-statement, externally controllable transaction. BeginTransaction() therefore throws NotSupportedException so callers learn immediately that IDbContextTransaction cannot be obtained.
Solutions
- Remove the explicit transaction usage for Cosmos contexts; rely on the provider's batch atomicity within a partition.
- Branch the data-access code so Cosmos does not call BeginTransaction (use AutoTransactionBehavior.Never or the default).
- If cross-document atomicity is required, ensure all writes target the same partition key and use a single SaveChanges call (transactional batch).
Example fix
// before
using var tx = dbContext.Database.BeginTransaction();
try { await dbContext.SaveChangesAsync(); tx.Commit(); }
catch { tx.Rollback(); throw; }
// after - no explicit transaction for Cosmos
await dbContext.SaveChangesAsync();
// (atomicity is provided by a single-partition transactional batch when applicable) Defensive patterns
Strategy: validation
Validate before calling
if (dbContext.Database.ProviderName == "Microsoft.EntityFrameworkCore.Cosmos")
{
// do NOT open a transaction; proceed without one
}
else
{
using var tx = dbContext.Database.BeginTransaction();
// ... save + commit
} Prevention
- Branch data-access code to skip transactions for Cosmos.
- Avoid generic transaction wrappers that assume a relational provider.
- Document the no-transaction limitation for Cosmos in your data-access layer.
When it happens
Trigger: Calling dbContext.Database.BeginTransaction() on a Cosmos provider. Triggered by shared code (e.g. a unit-of-work wrapper) that opens a transaction for relational providers and is reused against Cosmos.
Common situations: Generic repositories/unit-of-work that always wrap saves in a transaction. Migrating relational code that uses BeginTransaction. TransactionScope usage that resolves to this provider.
Related errors
- The Cosmos database does not support 'CanConnect' or…
- A call was made to ' ' that changed an option that must be…
- A FromSqlExpression has an invalid arguments expression type
- A full-text index is defined for
- A full-text index on
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/0d1a5ad69de085cf.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Cosmos/Storage/Internal/CosmosTransactionManager.cs:24
namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal;
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public class CosmosTransactionManager : IDbContextTransactionManager, ITransactionEnlistmentManager
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual IDbContextTransaction BeginTransaction()
=> throw new NotSupportedException(CosmosStrings.TransactionsNotSupported);
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual Task<IDbContextTransaction> BeginTransactionAsync(
CancellationToken cancellationToken = default)
=> throw new NotSupportedException(CosmosStrings.TransactionsNotSupported);
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual void CommitTransaction()View on GitHub (pinned to 3a2006ef56)