Skip to content

Read vector dimensions when scaffolding SQL Server databases below compatibility level 170 - #39162

Merged
AndriySvyryd merged 2 commits into
dotnet:mainfrom
tunahanaliozturk:fix/38763-vector-scaffold
Oct 8, 2026
Merged

AndriySvyryd merged 2 commits into
dotnet:mainfrom
tunahanaliozturk:fix/38763-vector-scaffold

Conversation

@tunahanaliozturk

Copy link
Copy Markdown
Contributor

Fixes #38763

The SQL Server vector type is available under all database compatibility levels, but the scaffolder only read sys.columns.vector_dimensions when the database was at compatibility level 170 or higher. On SQL Server 2025 or Azure SQL databases at a lower level (for example a database upgraded from SQL Server 2022, which stays at 160), vector columns were scaffolded as vector(0), and scaffolding then failed with "Vector properties require a positive size (number of dimensions)".

The dimensions are now read whenever the server has the vector type, based on the type aliases the factory already loads from sys.types, instead of the compatibility level. No extra query is added.

Added Vector_type_with_compatibility_level_below_170, which lowers the test database to compatibility level 160, scaffolds a vector(3) column and checks the store type and the mapped size. It fails with vector(0) on main. Like the existing Vector_type test, it runs only where IsVectorTypeSupported is true.

…mpatibility level 170

The vector type is available under all database compatibility levels, but the
scaffolder only read sys.columns.vector_dimensions when the compatibility level
was 170 or higher. On a SQL Server 2025 or Azure SQL database at a lower level,
vector columns were scaffolded as vector(0), which the type mapping then
rejected with "Vector properties require a positive size". Read the dimensions
whenever the server has the vector type instead.

Fixes dotnet#38763
Copilot AI balanced review requested due to automatic review settings October 4, 2026 21:59
@tunahanaliozturk
tunahanaliozturk requested a review from a team as a code owner October 4, 2026 21:59

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.

Copilot review overview

🟡 Changes recommended

Setup failures can leave the shared test database at compatibility level 160.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes SQL Server vector scaffolding below compatibility level 170 by detecting type availability rather than database compatibility.

Changes:

  • Uses loaded type metadata to decide whether to read vector dimensions.
  • Adds regression coverage at compatibility level 160.
File Description
test/​EFCore.SqlServer.FunctionalTests/​Scaffolding/​SqlServerDatabaseModelFactoryTest.cs Verifies vector dimensions and mapped size at level 160.
src/​EFCore.SqlServer/​Scaffolding/​Internal/​SqlServerDatabaseModelFactory.cs Gates dimension reads on vector type availability.

…f setup fails

The fixture database is shared, so the level is now restored in an outer finally instead of in the table cleanup script, which is skipped when the setup itself fails.
Copilot AI balanced review requested due to automatic review settings October 4, 2026 22:46

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.

Copilot review overview

🟢 Approval recommended

The focused fix addresses the reported failure, includes regression coverage, and leaves no unresolved findings.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@AndriySvyryd AndriySvyryd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution!

@AndriySvyryd
AndriySvyryd merged commit 07addc7 into dotnet:main Oct 8, 2026
19 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 9, 2026
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.

scaffold vs Sql Server [Embedding] [vector](1536, float32)

3 participants