Skip to content

Don’t scaffold string concatenation defaults as a single string literal - #39318

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/scaffold-string-concatenation-default
Oct 21, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/scaffold-string-concatenation-default

Conversation

@ilkertskn

Copy link
Copy Markdown
Contributor

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.

  • [ x] I've read the guidelines for contributing and seen the walkthrough
  • [x ] I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • [ x] The code builds and tests pass locally (also verified by our automated build checks)
  • [x ] Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • [x ] Tests for the changes have been added (for bug fixes / features)
  • [x ] Code follows the same patterns and style as existing code in this repo

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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
AndriySvyryd merged commit a836845 into dotnet:main Oct 21, 2026
20 checks passed
@AndriySvyryd

Copy link
Copy Markdown
Member

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants