Add KeysUniqueAcrossSchemas property to SharedTableConvention#37861
Merged
AndriySvyryd merged 6 commits intomainfrom Mar 9, 2026
Merged
Add KeysUniqueAcrossSchemas property to SharedTableConvention#37861AndriySvyryd merged 6 commits intomainfrom
AndriySvyryd merged 6 commits intomainfrom
Conversation
Add a new protected virtual bool property KeysUniqueAcrossSchemas (default true) that controls whether key constraint names must be unique across schemas. Group the table iteration by schema and clear the keys dictionary at schema boundaries when KeysUniqueAcrossSchemas is false. Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add KeysUniqueAcrossSchemas property to SharedTableConvention
Add KeysUniqueAcrossSchemas property to SharedTableConvention
Mar 5, 2026
AndriySvyryd
reviewed
Mar 5, 2026
Add SharedTableConventionTest with two tests: - Keys_are_not_uniquified_across_schemas_when_KeysUniqueAcrossSchemas_is_false - Keys_are_uniquified_across_schemas_when_KeysUniqueAcrossSchemas_is_true Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
AndriySvyryd
reviewed
Mar 5, 2026
test/EFCore.Relational.Tests/Metadata/Conventions/SharedTableConventionTest.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a new KeysUniqueAcrossSchemas customization point to SharedTableConvention and introduces tests validating key name uniqueness behavior across schemas.
Changes:
- Introduce
SharedTableConvention.KeysUniqueAcrossSchemas(defaulttrue) to control key name uniqueness across schemas. - Update
ProcessModelFinalizingto optionally reset key-name uniquification per schema. - Add tests covering both default behavior and
KeysUniqueAcrossSchemas = false.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs | Adds KeysUniqueAcrossSchemas and changes table iteration to support per-schema key uniquification. |
| test/EFCore.Relational.Tests/Metadata/Conventions/SharedTableConventionTest.cs | Adds tests asserting key name behavior across schemas for both default and overridden convention behavior. |
You can also share your feedback on Copilot code review. Take the survey.
src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Relational.Tests/Metadata/Conventions/SharedTableConventionTest.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Relational.Tests/Metadata/Conventions/SharedTableConventionTest.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Relational.Tests/Metadata/Conventions/SharedTableConventionTest.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
You can also share your feedback on Copilot code review. Take the survey.
roji
approved these changes
Mar 7, 2026
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.
When
KeysUniqueAcrossTablesistrue, key constraint names are currently enforced unique across all tables regardless of schema. Databases like PostgreSQL scope constraint name uniqueness per-schema, so this produces unnecessary renames. See npgsql/efcore.pg#3704.protected virtual bool KeysUniqueAcrossSchemas => truetoSharedTableConvention, following the existing*UniqueAcrossTablesproperty patternProcessModelFinalizingby schema; clear thekeysdictionary at schema boundaries whenKeysUniqueAcrossSchemasisfalsetruepreserves existing behavior; providers override tofalseas neededSharedTableConventionTestwith tests verifying both the override tofalse(keys not uniquified across schemas) and the defaulttruebehavior (keys uniquified across schemas), using the finalized model for assertions✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.