Skip to content

GetIndexesQuery: Exclude expression indexes at the database level. Fix #1188.#1262

Open
fdcastel wants to merge 1 commit intoFirebirdSQL:masterfrom
fdcastel:fix-issue-1188
Open

GetIndexesQuery: Exclude expression indexes at the database level. Fix #1188.#1262
fdcastel wants to merge 1 commit intoFirebirdSQL:masterfrom
fdcastel:fix-issue-1188

Conversation

@fdcastel
Copy link
Member

FbDatabaseModelFactory.GetIndexes uses table.Columns.Single(...) to look up index columns by name. Expression-based indexes (e.g., COMPUTED BY (upper(col))) don't have real column entries in RDB$INDEX_SEGMENTS — their segment names don't match any table column — causing Single() to throw "Sequence contains no matching element".

Changes

FbDatabaseModelFactory.cs:

  1. SQL query — Added AND i.RDB$EXPRESSION_SOURCE IS NULL to GetIndexesQuery to exclude expression indexes at the database level. Expression indexes can't be meaningfully represented in EF Core's scaffolded model anyway.
  2. Code safety — Added a null/empty check for the COLUMNS value before iterating, using reader.IsDBNull(3) and string.IsNullOrEmpty() to skip indexes with no segments gracefully.

ScaffoldingTests.cs:

  • ExpressionIndexDoesNotBreakScaffolding — Creates a table with an expression index and verifies scaffolding completes without throwing, and the expression index is excluded from the model.
  • RegularIndexScaffoldedAlongsideExpressionIndex — Creates a table with both a regular and an expression index, verifying the regular index is scaffolded correctly while the expression index is excluded.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant