Repository navigation
Allow multiple EntityTypeConfigurationAttribute declarations on entity types - #39506
Merged
AndriySvyryd merged 1 commit intoNov 17, 2026
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain, and the changes include focused implementation updates with tests covering multiple, duplicate, invalid, partial, and inheritance scenarios.
No open issues 🎉
What changed in this PR
This pull request enables multiple EntityTypeConfigurationAttribute declarations on an entity, supporting modular and source-generated configuration across partial classes while preventing inherited configuration attributes from applying to derived types.
Changes:
- Allows repeated non-generic and generic attribute declarations with
AllowMultiple = trueandInherited = false. - Processes all direct configuration attributes and deduplicates configuration types per entity.
- Adds tests for multiple, mixed, partial, duplicate, invalid, and inheritance scenarios.
- Includes a minor test-coverage note to verify inherited model facets remain visible on derived types.
| File | Summary |
|---|---|
test/EFCore.Tests/Metadata/Conventions/EntityTypeConfigurationAttributeConventionTest.cs |
Adds coverage for multiple configurations, partial classes, deduplication, mixed attributes, invalid configurations, and inheritance behavior. |
src/EFCore/Metadata/Conventions/EntityTypeConfigurationAttributeConvention.cs |
Processes direct configuration attributes and applies each distinct configuration type once. |
src/EFCore/EntityTypeConfigurationAttribute.cs |
Allows multiple non-inherited generic configuration attribute declarations. |
src/EFCore.Abstractions/EntityTypeConfigurationAttribute.cs |
Allows multiple non-inherited non-generic configuration attribute declarations. |
Review effort: Lite
AndriySvyryd
reviewed
Nov 4, 2026
Manish-1kumar
force-pushed
the
feature/issue-34710-multiple-entity-configuration-attributes
branch
from
November 4, 2026 08:58
ab6fd0a to
4a0d801
Compare
AndriySvyryd
approved these changes
Nov 17, 2026
AndriySvyryd
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution!
Manish-1kumar
deleted the
feature/issue-34710-multiple-entity-configuration-attributes
branch
December 2, 2026 03:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #34710
Enables multiple
[EntityTypeConfiguration]declarations on a single entity type, allowing independent source generators and modular configuration classes acrosspartial classdefinitions.Key Architectural Decisions
AllowMultiple = true, Inherited = false:Both
EntityTypeConfigurationAttribute(EFCore.Abstractions) andEntityTypeConfigurationAttribute<TConfiguration, TEntity>(EFCore) are updated withAllowMultiple = true, Inherited = false.Inherited = falseis critical: becauseIEntityTypeConfiguration<T>is strictly bound toT, inheriting base-class attributes on derived types would fail the interface type validation withInvalidOperationException. SettingInherited = falseensures base classes configure base types and derived classes configure derived types, while preserving model-level facet inheritance.Deduplication:
EntityTypeConfigurationAttributeConventionoverridesProcessEntityTypeAddedto deduplicate byattribute.EntityTypeConfigurationTypeper entity type using a localHashSet<Type>, ensuring identical configurations specified across partial classes only invokeConfigure()once.Ordering:
Per C# Language Specification §14.2.1, attribute ordering across partial types is explicitly unspecified. Multiple configurations execute sequentially in the order discovered with
ConfigurationSource.Explicitsemantics, with formal topological ordering remaining aligned with Allow to specify dependencies in IEntityTypeConfiguration #22035.Zero Impact on Other Conventions:
TypeAttributeConventionBaseis left untouched, isolating this change exclusively toEntityTypeConfigurationAttributeConvention.Customer Impact
Developers and source generator authors can now annotate multiple partial declarations of an entity with independent
[EntityTypeConfiguration]attributes without encounteringCS0579: Duplicate 'EntityTypeConfiguration' attribute.Testing
EntityTypeConfigurationAttributeConventionTest.Microsoft.EntityFrameworkCore.Metadata.ConventionsandApiConsistencyTestpass locally.