{"record":{"id":"7d4579b8b16800ea","repo":"dotnet/efcore","slug":"explicitly-named-default-constraints-cannot-be-use","errorCode":null,"errorMessage":"Explicitly named default constraints cannot be used with TPC inheritance or entity splitting. Constraint name: '{explicitDefaultConstraintName}'.","messagePattern":"Explicitly named default constraints cannot be used with TPC inheritance or entity splitting\\. Constraint name: '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs","lineNumber":772,"sourceCode":"        string? schema,\n        Dictionary<(string, string?), (IConventionProperty, StoreObjectIdentifier)> defaultConstraints,\n        in StoreObjectIdentifier storeObject,\n        int maxLength)\n    {\n        var mappedTables = property.GetMappedStoreObjects(StoreObjectType.Table);\n        if (mappedTables.Count() > 1)\n        {\n            // For TPC and some entity splitting scenarios we end up with multiple tables having to define the constraint.\n            // Since constraint name has to be unique, we can't keep the same name for all\n            // Disabling this scenario until we have better way to configure the constraint name\n            // see issue #27970\n            if (property.GetDefaultConstraintNameConfigurationSource() == null)\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.ImplicitDefaultNamesNotSupportedForTpcWhenNamesClash(constraintName));\n            }\n\n            throw new InvalidOperationException(\n                RelationalStrings.ExplicitDefaultConstraintNamesNotSupportedForTpc(constraintName));\n        }\n\n        if (property.Builder.CanSetAnnotation(RelationalAnnotationNames.DefaultConstraintName, null))\n        {\n            constraintName = Uniquifier.Uniquify(constraintName, defaultConstraints, n => (n, schema), maxLength);\n            property.Builder.HasAnnotation(RelationalAnnotationNames.DefaultConstraintName, constraintName);\n            return constraintName;\n        }\n\n        return null;\n    }\n\n    private void UniquifyTriggerNames(\n        IConventionEntityType entityType,\n        Dictionary<string, (IConventionTrigger, StoreObjectIdentifier)> triggers,\n        in StoreObjectIdentifier storeObject,\n        int maxLength)","sourceCodeStart":754,"sourceCodeEnd":790,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs#L754-L790","documentation":"The companion to [458]: when a property maps to multiple tables (TPC or entity splitting) AND an explicit default-constraint name HAS been configured, EF still throws ExplicitDefaultConstraintNamesNotSupportedForTpc. A single explicit name cannot be reused across tables (names must be unique), and EF does not yet support per-table explicit names, so even an explicitly named default constraint is unsupported in these scenarios (issue #27970).","triggerScenarios":"Setting .HasDefaultValue(v) (or HasDefaultValueSql) together with an explicit default-constraint name (.HasDefaultConstraintName(\"DF_X\")) on a property that maps to multiple tables under TPC inheritance or entity splitting.","commonSituations":"Trying to 'fix' [458] by naming the constraint; copying default-constraint naming from TPH code into a TPC hierarchy; split entities with named defaults.","solutions":["Remove the default value/SQL (and the explicit name) from the shared property so no default constraint is generated on multiple tables.","Remap the property to a single table (switch TPC -> TPH, or un-split) if the default is essential.","Move the default-bearing property onto a non-shared entity so it occupies one table.","Await issue #27970 for per-table explicit default-constraint name support."],"exampleFix":"// before — explicit default-constraint name on a TPC-shared property -> [459]\nmodelBuilder.Entity<Animal>().UseTpcMapping()\n    .Property(a => a.Legs)\n    .HasDefaultValue(4)\n    .HasDefaultConstraintName(\"DF_Animal_Legs\");\n\n// after — no default constraint on the shared property\nmodelBuilder.Entity<Animal>().UseTpcMapping()\n    .Property(a => a.Legs);\n// set Animal.Legs = 4 in the constructor/OnModelCreating seed data instead","handlingStrategy":"validation","validationCode":"// Detect explicitly-named default constraints on properties mapped to multiple tables.\nstatic IEnumerable<IProperty> PropertiesWithExplicitNamedDefaultsOnMultiTable(IModel model)\n    => model.GetEntityTypes()\n        .SelectMany(et => et.GetProperties())\n        .Where(p => p.GetMappedStoreObjects(StoreObjectType.Table).Count() > 1\n                    && p.GetDefaultConstraintNameConfigurationSource() is not null);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not combine explicit default-constraint names with TPC/entity splitting (issue #27970).","Drop the default value entirely on multi-table-mapped properties, or remap to a single table.","Move default-bearing properties onto non-shared entities."],"tags":["default-constraints","tpc","entity-splitting","conventions"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}