Repository navigation
SQL Server migrations should use QUOTENAME when constructing SQL for EXEC - #36271
Merged
Merged
Conversation
duncansmart
force-pushed
the
efcore-issue-36264
branch
2 times, most recently
from
June 20, 2025 09:58
6e4f2ed to
b7567fc
Compare
roji
requested changes
Jun 20, 2025
Contributor
Author
|
It also makes me realise that |
…EXEC * Refactor `SqlServerMigrationsSqlGenerator.cs` to use `QUOTENAME` when generating dynamic SQL passed to EXEC, improving safety and correctness in SQL command generation. * Update related tests to ensure expected SQL output aligns with these changes. Fixes dotnet#36264
duncansmart
force-pushed
the
efcore-issue-36264
branch
from
June 21, 2025 18:44
b7567fc to
17e2d21
Compare
Member
|
@duncansmart just a remind that if your PR is ready for another review, please ask for one explicitly ("re-request review" button in top-right corner, under "Reviewers"). |
roji
enabled auto-merge (squash)
June 23, 2025 06:44
cincuranet
added a commit
to cincuranet/efcore
that referenced
this pull request
Jun 26, 2025
cincuranet
added a commit
that referenced
this pull request
Jun 26, 2025
m-x-shokhzod
added a commit
to m-x-shokhzod/efcore
that referenced
this pull request
May 31, 2026
Addresses Copilot review on dotnet#38250: the variable was changed from nvarchar(max) to sysname, but the SELECT still stores QUOTENAME(...) whose output can reach 258 chars and would silently truncate inside a 128-char sysname, producing invalid DROP CONSTRAINT SQL for long names. The variable-type change was never part of issue dotnet#34620, which only asks to replace the sys.default_constraints JOIN with a single-table lookup via OBJECT_NAME([c].[default_object_id]). QUOTENAME is required here by dotnet#36271 (use QUOTENAME when constructing SQL for EXEC), so the matching nvarchar(max) must stay. Revert the variable to nvarchar(max) and keep only the lookup simplification. Restore the nvarchar(max) baseline in all affected test expectations.
m-x-shokhzod
added a commit
to m-x-shokhzod/efcore
that referenced
this pull request
Jun 9, 2026
Replace the JOIN against [sys].[default_constraints] + [sys].[columns] with a single-table lookup on [sys].[columns] via OBJECT_NAME([c].[default_object_id]). One sys-table, no JOIN; behavior is preserved (OBJECT_NAME returns NULL when there is no default constraint, so the existing IF @var IS NOT NULL guard still skips the drop). The nvarchar(max) variable and QUOTENAME wrapping are kept: QUOTENAME's output can exceed sysname's 128 chars, and QUOTENAME is required when constructing the dynamic SQL passed to EXEC (dotnet#36271). Fixes dotnet#34620
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 #36264