Repository navigation
Make model snapshots with mismatched FK/PK property types usable - #38450
Merged
Merged
Conversation
Co-authored-by: AndriySvyryd <[email protected]>
Co-authored-by: AndriySvyryd <[email protected]>
Copilot
AI
changed the title
[WIP] Fix foreign keys with different types from primary keys
Validate that foreign key property types match principal key property types
Jun 17, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds core model validation to reject foreign keys whose provider CLR types don’t match the referenced principal key’s provider CLR types, aligning runtime behavior with maintainer guidance while continuing to implicitly skip validation for model snapshots.
Changes:
- Introduces a new
ModelValidator.ValidateForeignKeyspass that compares dependent vs. principal provider CLR types and throwsCoreStrings.ForeignKeyTypeMismatchon mismatches. - Adds/updates tests to cover matching vs. mismatched provider-type scenarios and updates relational tests impacted by earlier validation failure.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/EFCore/Infrastructure/ModelValidator.cs | Adds provider-type FK validation during model validation. |
| test/EFCore.Tests/Infrastructure/ModelValidatorTest.cs | Adds unit tests for matching/mismatched provider-type FK validation. |
| test/EFCore.Relational.Tests/Storage/RelationalTypeMappingTest.cs | Updates a relational mapping test to expect the new FK provider-type validation failure. |
| test/EFCore.Relational.Tests/Infrastructure/RelationalModelValidatorTest.cs | Updates a relational validator test impacted by the new earlier FK validation behavior. |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
…pe roundtrip Co-authored-by: AndriySvyryd <[email protected]>
Co-authored-by: AndriySvyryd <[email protected]>
Co-authored-by: AndriySvyryd <[email protected]>
Co-authored-by: AndriySvyryd <[email protected]>
Co-authored-by: AndriySvyryd <[email protected]>
Co-authored-by: AndriySvyryd <[email protected]>
Co-authored-by: AndriySvyryd <[email protected]>
Copilot
AI
changed the title
Allow foreign key property types to not match principal key property types exactly in snapshots
Make model snapshots with mismatched FK/PK property types usable
Jun 18, 2026
AndriySvyryd
marked this pull request as ready for review
June 18, 2026 02:41
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
cincuranet
approved these changes
Jun 19, 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.
Fixes #30827
Per maintainer feedback, this PR no longer adds foreign key/principal key type enforcement in
ModelValidator. Instead, it focuses on snapshot compatibility so existing snapshots with mismatched key/foreign-key property CLR types can still build a usable model.Changes
ModelValidator.ValidateForeignKeyscheck and its invocation.Model.IsInModelSnapshot, and updated compatibility checks to use it.Snapshot_with_mismatched_key_and_foreign_key_property_types_is_usable.Scope
This PR is now strictly about model snapshot compatibility.
It does not introduce new runtime FK/PK type validation in
ModelValidator.