{"record":{"id":"0d1a5ad69de085cf","repo":"dotnet/efcore","slug":"the-cosmos-database-provider-does-not-support-tran","errorCode":null,"errorMessage":"The Cosmos database provider does not support transactions.","messagePattern":"The Cosmos database provider does not support transactions\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Storage/Internal/CosmosTransactionManager.cs","lineNumber":24,"sourceCode":"\nnamespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal;\n\n/// <summary>\n///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n///     any release. You should only use it directly in your code with extreme caution and knowing that\n///     doing so can result in application failures when updating to a new Entity Framework Core release.\n/// </summary>\npublic class CosmosTransactionManager : IDbContextTransactionManager, ITransactionEnlistmentManager\n{\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual IDbContextTransaction BeginTransaction()\n        => throw new NotSupportedException(CosmosStrings.TransactionsNotSupported);\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual Task<IDbContextTransaction> BeginTransactionAsync(\n        CancellationToken cancellationToken = default)\n        => throw new NotSupportedException(CosmosStrings.TransactionsNotSupported);\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual void CommitTransaction()","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Storage/Internal/CosmosTransactionManager.cs#L6-L42","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nusing var tx = dbContext.Database.BeginTransaction();\ntry { await dbContext.SaveChangesAsync(); tx.Commit(); }\ncatch { tx.Rollback(); throw; }\n\n// after - no explicit transaction for Cosmos\nawait dbContext.SaveChangesAsync();\n// (atomicity is provided by a single-partition transactional batch when applicable)","handlingStrategy":"validation","validationCode":"if (dbContext.Database.ProviderName == \"Microsoft.EntityFrameworkCore.Cosmos\")\n{\n    // do NOT open a transaction; proceed without one\n}\nelse\n{\n    using var tx = dbContext.Database.BeginTransaction();\n    // ... save + commit\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cosmos","transactions","notsupported","begintransaction"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}