dotnet/efcore · error · InvalidOperationException

Both ' ' and ' ' are mapped to the stored procedure ' '…

Error message

Both '{entityType}' and '{otherEntityType}' are mapped to the stored procedure '{sproc}'. All the entity types in a non-TPH hierarchy (one that doesn't have a discriminator) must be mapped to different stored procedures. See https://go.microsoft.com/fwlink/?linkid=2130430 for more information.

What it means

Thrown inside ValidateNonTphMapping when two entity types in a non-TPH hierarchy resolve to the same Insert/Delete/Update stored procedure StoreObjectIdentifier. In TPT/TPC each type must have its own distinct stored procedure for each operation; sharing is rejected.

Solutions

  1. Map each type to its own stored procedure name in a non-TPH hierarchy.
  2. Switch to TPH (with the sproc defined on the root) if you want a single shared stored procedure.
  3. Remove duplicate *UsingStoredProcedure configuration and let each type define its own.

Example fix

// before (TPT, shared sproc)
modelBuilder.UseTptMappingStrategy();
modelBuilder.Entity<Customer>().InsertUsingStoredProcedure("sp_Upsert");
modelBuilder.Entity<Vendor>().InsertUsingStoredProcedure("sp_Upsert"); // throws 428

// after
modelBuilder.Entity<Customer>().InsertUsingStoredProcedure("sp_InsertCustomer");
modelBuilder.Entity<Vendor>().InsertUsingStoredProcedure("sp_InsertVendor");
Defensive patterns

Strategy: validation

Validate before calling

foreach (var root in modelBuilder.Model.GetEntityTypes().Where(t => t.BaseType == null))
{
    var strategy = root.GetMappingStrategy();
    if (strategy != RelationalAnnotationNames.TptMappingStrategy
        && strategy != RelationalAnnotationNames.TpcMappingStrategy) continue;
    foreach (var sot in new[] { StoreObjectType.InsertStoredProcedure, StoreObjectType.DeleteStoredProcedure, StoreObjectType.UpdateStoredProcedure })
    {
        var sprocs = new HashSet<string>();
        foreach (var et in root.GetDerivedTypesInclusive())
        {
            var so = StoreObjectIdentifier.Create(et, sot);
            if (so != null && !sprocs.Add(so.Value.Name))
                throw new InvalidOperationException($"Sproc '{so.Value.Name}' ({sot}) used by multiple types in {root.DisplayName()}.");
        }
    }
}

Prevention

When it happens

Trigger: Two types in a TPT/TPC hierarchy both call InsertUsingStoredProcedure("sproc")/DeleteUsingStoredProcedure/UpdateUsingStoredProcedure with the same name; sibling types resolving to the same sproc.

Common situations: Centralizing CRUD into shared stored procedures while using TPT/TPC; copy-pasting stored procedure mappings; assuming one sproc can serve the whole non-TPH hierarchy.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/800ef22109d3ecf6. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs:2251

                continue;
            }

            if (derivedTypes.TryGetValue(storeObject.Value, out var otherType))
            {
                switch (storeObjectType)
                {
                    case StoreObjectType.Table:
                        throw new InvalidOperationException(
                            RelationalStrings.NonTphTableClash(
                                entityType.DisplayName(), otherType.DisplayName(), storeObject.Value.DisplayName()));
                    case StoreObjectType.View:
                        throw new InvalidOperationException(
                            RelationalStrings.NonTphViewClash(
                                entityType.DisplayName(), otherType.DisplayName(), storeObject.Value.DisplayName()));
                    case StoreObjectType.InsertStoredProcedure:
                    case StoreObjectType.DeleteStoredProcedure:
                    case StoreObjectType.UpdateStoredProcedure:
                        throw new InvalidOperationException(
                            RelationalStrings.NonTphStoredProcedureClash(
                                entityType.DisplayName(), otherType.DisplayName(), storeObject.Value.DisplayName()));
                }
            }

            if (isTpc)
            {
                var rowInternalFk = entityType.FindDeclaredReferencingRowInternalForeignKeys(storeObject.Value)
                    .FirstOrDefault();
                if (rowInternalFk != null
                    && entityType.GetDirectlyDerivedTypes().Any())
                {
                    throw new InvalidOperationException(
                        RelationalStrings.TpcTableSharing(
                            rowInternalFk.DeclaringEntityType.DisplayName(),
                            storeObject.Value.DisplayName(),
                            rowInternalFk.PrincipalEntityType.DisplayName()));
                }

View on GitHub (pinned to 3a2006ef56)