Repository navigation
Don’t scaffold string concatenation defaults as a single string literal - #39318
Merged
AndriySvyryd merged 1 commit intoOct 21, 2026
Merged
AndriySvyryd merged 1 commit into
AndriySvyryd merged 1 commit into
Conversation
SqlServerDatabaseModelFactory and SqliteDatabaseModelFactory treated any default
that starts and ends with a quote as one string literal. A default such as
DEFAULT N'a' + N'b' (SQL Server) or DEFAULT ('a' || 'b') (SQLite) was therefore
scaffolded as HasDefaultValue("a'+N'b") instead of HasDefaultValueSql, and a
migration generated from that model writes the corrupted value to the database.
Defaults whose body contains an unescaped quote are now left as SQL.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The reviewed changes and regression tests consistently address the default-value scaffolding issue without unresolved blocking concerns.
No open issues 🎉
What changed in this PR
This pull request fixes reverse engineering of SQL Server and SQLite string-concatenation defaults so they remain SQL expressions instead of being incorrectly scaffolded as corrupted CLR string values.
Changes:
- Detects unescaped quotes in apparent string literals and preserves expressions as SQL defaults.
- Updates SQL Server and SQLite scaffolding logic.
- Adds regression coverage for concatenation and escaped-quote scenarios.
| File | Description |
|---|---|
test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs |
Verifies SQL Server concatenated defaults remain SQL through database-model and scaffolding-model creation. |
test/EFCore.Sqlite.FunctionalTests/Scaffolding/SqliteDatabaseModelFactoryTest.cs |
Verifies SQLite concatenation defaults remain SQL expressions. |
src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs |
Prevents SQL Server concatenation expressions from being parsed as CLR string defaults. |
src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs |
Prevents SQLite concatenation expressions from being parsed as CLR string defaults. |
Review effort: Lite
AndriySvyryd
approved these changes
Oct 21, 2026
Member
|
Thanks for your contribution! |
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.
SqlServerDatabaseModelFactory and SqliteDatabaseModelFactory treated any default that starts and ends with a quote as one string literal. A default such as DEFAULT N'a' + N'b' (SQL Server) or DEFAULT ('a' || 'b') (SQLite) was therefore scaffolded as HasDefaultValue("a'+N'b") instead of HasDefaultValueSql, and a migration generated from that model writes the corrupted value to the database. Defaults whose body contains an unescaped quote are now left as SQL.