{"record":{"id":"afb5991ff96a4b80","repo":"dotnet/efcore","slug":"both-entity-type-entitytype1-and-entitytype2","errorCode":null,"errorMessage":"Both entity type '{entityType1}' and '{entityType2}' were configured to use '{sproc}', stored procedure sharing is not supported. Specify different names for the corresponding stored procedures.","messagePattern":"Both entity type '(.+?)' and '(.+?)' were configured to use '(.+?)', stored procedure sharing is not supported\\. Specify different names for the corresponding stored procedures\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":553,"sourceCode":"        IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)\n        => ValidateStoredProcedureCompatibility(mappedTypes, storedProcedure, logger);\n\n    /// <summary>\n    ///     Validates that a stored procedure is not shared across unrelated entity types.\n    /// </summary>\n    /// <param name=\"mappedTypes\">The entity types mapped to the stored procedure.</param>\n    /// <param name=\"storedProcedure\">The stored procedure identifier.</param>\n    /// <param name=\"logger\">The logger to use.</param>\n    protected virtual void ValidateStoredProcedureCompatibility(\n        IReadOnlyList<IEntityType> mappedTypes,\n        in StoreObjectIdentifier storedProcedure,\n        IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)\n    {\n        foreach (var mappedType in mappedTypes)\n        {\n            if (mappedTypes[0].GetRootType() != mappedType.GetRootType())\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.StoredProcedureTableSharing(\n                        mappedTypes[0].DisplayName(),\n                        mappedType.DisplayName(),\n                        storedProcedure.DisplayName()));\n            }\n        }\n    }\n\n    private static void ValidateSproc(\n        IStoredProcedure sproc,\n        string mappingStrategy,\n        IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)\n    {\n        var entityType = sproc.EntityType;\n        var storeObjectIdentifier = sproc.GetStoreIdentifier();\n\n        var primaryKey = entityType.FindPrimaryKey();\n        if (primaryKey == null)","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L535-L571","documentation":"Thrown by ValidateStoredProcedureCompatibility when two entity types with different root types are mapped to the same stored procedure. Stored procedure sharing is only permitted within a single inheritance hierarchy (same root type, e.g. TPH); unrelated types cannot reuse one sproc.","triggerScenarios":"Two independent entities both calling .InsertStoredProcedure(\"sp_Save\") with the identical name; accidental name collision across unrelated entities.","commonSituations":"Naming conventions that produce the same sproc name for different tables; copy-pasting sproc config between entities.","solutions":["Give each unrelated entity type a distinct stored procedure name.","Only share a sproc name across entities that belong to the same inheritance hierarchy.","Audit all ToStoredProcedure/Insert/Update/Delete calls for duplicate names across non-hierarchy types."],"exampleFix":"// before\nmodelBuilder.Entity<Blog>().InsertStoredProcedure(\"sp_Save\");\nmodelBuilder.Entity<Post>().InsertStoredProcedure(\"sp_Save\"); // unrelated\n\n// after\nmodelBuilder.Entity<Blog>().InsertStoredProcedure(\"sp_InsertBlog\");\nmodelBuilder.Entity<Post>().InsertStoredProcedure(\"sp_InsertPost\");","handlingStrategy":"validation","validationCode":"var byName = new Dictionary<string, string>();\nforeach (var et in modelBuilder.Model.GetEntityTypes())\n{\n    foreach (var s in new[] { et.GetInsertStoredProcedure(), et.GetUpdateStoredProcedure(), et.GetDeleteStoredProcedure() }.Where(s => s != null))\n    {\n        var id = s.GetStoreIdentifier();\n        if (byName.TryGetValue(id.Name, out var other) && other != et.GetRootType().Name)\n            throw new InvalidOperationException($\"Sproc {id.Name} shared across unrelated types\");\n        byName[id.Name] = et.GetRootType().Name;\n    }\n}","typeGuard":null,"tryCatchPattern":"try { _ = ctx.Model; } catch (InvalidOperationException ex) when (ex.Message.Contains(\"stored procedure sharing is not supported\")) { /* rename the colliding sproc */ }","preventionTips":["Use per-entity sproc naming conventions (e.g. sp_Insert<EntityName>).","Audit sproc names across the model in a test to catch cross-hierarchy collisions."],"tags":["ef-core","stored-procedures","mapping","inheritance","model-validation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}