dotnet/efcore · error · InvalidOperationException

The provisioned throughput was configured to '{throughput1}'

Error message

The provisioned throughput was configured to '{throughput1}' on '{entityType1}', but on '{entityType2}' it was configured to '{throughput2}'. All entity types mapped to the same container '{container}' must be configured with the same provisioned throughput.

What it means

Thrown by CosmosModelValidator.ValidateSharedContainerCompatibility when two document-root entity types sharing a container declare different provisioned throughput values via HasThroughput(). The validator compares throughput.AutoscaleMaxThroughput ?? throughput.Throughput across types; a numeric mismatch throws. Throughput is a container-level Cosmos property, so EF forbids contradictory configuration.

Source

Thrown at src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs:287

                            conflictingEntityType.DisplayName(),
                            entityType.DisplayName(),
                            currentDefaultTtl,
                            container));
                }
            }

            var currentThroughput = entityType.GetThroughput();
            if (currentThroughput != null)
            {
                if (throughput == null)
                {
                    throughput = currentThroughput;
                }
                else if ((throughput.AutoscaleMaxThroughput ?? throughput.Throughput)
                         != (currentThroughput.AutoscaleMaxThroughput ?? currentThroughput.Throughput))
                {
                    var conflictingEntityType = mappedTypes.First(et => et.GetThroughput() != null);
                    throw new InvalidOperationException(
                        CosmosStrings.ThroughputMismatch(
                            throughput.AutoscaleMaxThroughput ?? throughput.Throughput,
                            conflictingEntityType.DisplayName(),
                            entityType.DisplayName(),
                            currentThroughput.AutoscaleMaxThroughput ?? currentThroughput.Throughput,
                            container));
                }
                else if (throughput.AutoscaleMaxThroughput
                         == null
                         != (currentThroughput.AutoscaleMaxThroughput == null))
                {
                    var conflictingEntityType = mappedTypes.First(et => et.GetThroughput() != null);
                    var autoscaleType = throughput.AutoscaleMaxThroughput == null
                        ? entityType
                        : conflictingEntityType;
                    var manualType = throughput.AutoscaleMaxThroughput != null
                        ? entityType
                        : conflictingEntityType;

View on GitHub (pinned to dbf9771522)

Solutions

  1. Set the same HasThroughput(RU) value on every root entity in the container.
  2. Set throughput on exactly one root entity and remove it from the rest.
  3. Consider database-level throughput instead of per-container if you need a single RU budget.

Example fix

// before
modelBuilder.Entity<Invoice>().ToContainer("billing").HasThroughput(400);
modelBuilder.Entity<Receipt>().ToContainer("billing").HasThroughput(1000);

// after
modelBuilder.Entity<Invoice>().ToContainer("billing").HasThroughput(1000);
modelBuilder.Entity<Receipt>().ToContainer("billing").HasThroughput(1000);
Defensive patterns

Strategy: validation

Validate before calling

using (var ctx = new MyContext()) { ctx.Model.GetModel(); }
foreach (var grp in ctx.Model.GetEntityTypes()
    .Where(e => e.FindPrimaryKey() != null && e.GetContainer() != null)
    .GroupBy(e => e.GetContainer()))
{
    var rru = grp.Select(e => e.GetThroughput()?.AutoscaleMaxThroughput ?? e.GetThroughput()?.Throughput).Distinct().ToList();
    Debug.Assert(rru.Count <= 1, $"Container {grp.Key} has conflicting throughput");
}

Try / catch

try { ctx.Model.GetModel(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("provisioned throughput was configured"))
{
    logger.LogError(ex, "Throughput mismatch in shared Cosmos container");
    throw;
}

Prevention

When it happens

Trigger: Calling modelBuilder.Entity<A>().HasThroughput(400) and modelBuilder.Entity<B>().HasThroughput(1000) where A and B share a container. Fires at model validation time.

Common situations: Tuning RU/s on one entity during load testing and forgetting the others in the shared container; different teams provisioning throughput independently for entities that end up co-located; merging two contexts that each set throughput.

Related errors


AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06). Data as JSON: /api/errors/502a4eb3309274df. Report an issue: GitHub.