Skip to content

Fix SQLite ExecuteUpdate with navigation properties and TPT inheritance#38023

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-sqlite-error-no-such-column
Draft

Fix SQLite ExecuteUpdate with navigation properties and TPT inheritance#38023
Copilot wants to merge 4 commits intomainfrom
copilot/fix-sqlite-error-no-such-column

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 27, 2026

SQLite doesn't support referencing the UPDATE target table in JOIN ON clauses within UPDATE...FROM. This breaks ExecuteUpdate when navigation properties or TPT inheritance produce JOINs that reference the target table in their ON predicates.

-- Generated SQL that fails on SQLite:
UPDATE "Animals" AS "a"
SET "Name" = @p
FROM "Birds" AS "b"
INNER JOIN "Kiwi" AS "k" ON "a"."Id" = "k"."Id"  -- "a" not resolvable here
WHERE "a"."Id" = "b"."Id"

Changes

  • SqliteQuerySqlGenerator.VisitUpdate — For multi-table UPDATEs, emits the target table without alias and lifts JOIN predicates that reference the target into the WHERE clause, converting those JOINs to comma-separated tables
  • SqliteQuerySqlGenerator.VisitTable — Suppresses alias generation for the UPDATE target table
  • SqliteQuerySqlGenerator.VisitColumn — Replaces column references to the target alias with the actual table name
  • ReferencesTargetTable — Walks JOIN predicates to detect references to the target table alias
-- Fixed SQL:
UPDATE "Animals"
SET "Name" = @p
FROM "Birds" AS "b", "Kiwi" AS "k"
WHERE "Animals"."Id" = "k"."Id" AND "Animals"."Id" = "b"."Id"

Test changes

  • Updated SQL baselines across NorthwindBulkUpdatesSqliteTest, NonSharedModelBulkUpdatesSqliteTest, and TPT inheritance test files
  • TPTInheritanceBulkUpdatesSqliteTest / TPTFiltersInheritanceBulkUpdatesSqliteTest: replaced Assert.ThrowsAsync<SqliteException> with proper execution + baseline assertions for Update_base_property_on_derived_type and Update_base_type_with_OfType

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits March 27, 2026 10:10
In multi-table UPDATE statements (with FROM clause), the UPDATE target
table no longer gets an alias, and column references use the table name
instead of the alias.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: roji <1862641+roji@users.noreply.github.com>
- Multi-table UPDATE statements no longer alias the target table
- Column references to the target alias now use the table name
- Fix Update_base_type_with_OfType and Update_base_property_on_derived_type
  tests in TPT and TPTFilters to call correct base methods with proper
  SQL baselines instead of expecting SqliteException (#31402)
- Remove unused Microsoft.Data.Sqlite import from TPT test files

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: roji <1862641+roji@users.noreply.github.com>
SQLite doesn't support referencing the UPDATE target table in JOIN ON
clauses within the FROM clause of UPDATE...FROM statements. This fix:

1. Overrides VisitUpdate in SqliteQuerySqlGenerator to not alias the
   UPDATE target table in multi-table UPDATE statements
2. Replaces column references to the target alias with the table name
3. Lifts JOIN predicates that reference the target table into the
   WHERE clause, emitting comma-separated tables instead of JOINs

This fixes both the navigation property issue and the TPT inheritance
issue (#31402).

Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/c9a7c8f9-9ec9-4305-abb2-e31de6da3f9d

Co-authored-by: roji <1862641+roji@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ExecuteUpdateAsync throwing SQLite Error 1 with navigation properties Fix SQLite ExecuteUpdate with navigation properties and TPT inheritance Mar 27, 2026
Copilot finished work on behalf of roji March 27, 2026 10:36
Copilot AI requested a review from roji March 27, 2026 10:36
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.

2 participants