Disable filter applying for Truncate, Drop.#5419
Merged
Conversation
Member
Author
|
/azp run test-all |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #5417 where Truncate and Drop operations fail with an InvalidCastException when used on tables that have global query filters applied (e.g., soft-delete filters in EF Core). The root cause was that the builders directly cast the build sequence result to TableContext, but when query filters are present, the result is a SubQueryContext wrapper instead.
Changes:
- Disable query filters when building sequences in
TruncateBuilderandDropBuilder, and useSequenceHelper.GetTableContext()to safely extract the table context instead of a direct cast. - Refactor
SequenceHelper.GetTableContextandGetTableOrCteContextto use the existingCreateRefhelper method. - Add a regression test that verifies
TruncateandDropwork correctly on tables with complex query filters.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Source/LinqToDB/Internal/Linq/Builder/TruncateBuilder.cs | Disable query filters during sequence building; use GetTableContext() instead of direct cast |
| Source/LinqToDB/Internal/Linq/Builder/DropBuilder.cs | Same fix as TruncateBuilder: disable filters and use safe table context extraction |
| Source/LinqToDB/Internal/Linq/Builder/SequenceHelper.cs | Minor refactoring to use CreateRef helper in GetTableContext and GetTableOrCteContext |
| Tests/Linq/Update/TruncateTableTests.cs | Adds regression test with a query-filtered entity for Truncate and Drop operations |
viceroypenguin
approved these changes
Mar 12, 2026
|
Test baselines changed by this PR. Don't forget to merge/close baselines PR after this pr merged/closed. |
MaceWindu
approved these changes
Mar 12, 2026
MaceWindu
added a commit
to linq2db/linq2db.baselines
that referenced
this pull request
Mar 12, 2026
* [Windows / SQL CE] baselines * [Windows / SQL Server 2005] baselines * [Windows / SQLite (both providers)] baselines * [Windows / Access MDB (Jet/ODBC)] baselines * [Windows / SQL Server 2012] baselines * [Windows / Access ACE (OLEDB/ODBC) x86] baselines * [Windows / SQL Server 2008] baselines * [Linux / Firebird 2.5] baselines * [Windows / SQL Server 2016] baselines * [Linux / DB2 LUW 11.5] baselines * [Linux / Firebird 3.0] baselines * [Linux / Informix 14.10] baselines * [Linux / Firebird 4.0] baselines * [Linux / Firebird 5.0] baselines * [Linux / MariaDB 11] baselines * [Windows / SQL Server 2014] baselines * [Linux / ClickHouse Driver] baselines * [Windows / SQL Server 2017] baselines * [Windows / SQL Server 2019] baselines * [Linux / ClickHouse MySql] baselines * [Linux / MySQL 5.7 (both providers)] baselines * [Linux / MySQL 9 (both providers)] baselines * [Linux / ClickHouse Octonica] baselines * [Linux / Oracle 11g XE] baselines * [Linux / PostgreSQL 13] baselines * [Linux / PostgreSQL 14] baselines * [Windows / SQL Server 2022] baselines * [Linux / Oracle 12c] baselines * [Linux / PostgreSQL 15] baselines * [Linux / Oracle 18c] baselines * [Linux / Oracle 23c] baselines * [Linux / Oracle 19c] baselines * [Linux / Oracle 21c] baselines * [Linux / PostgreSQL 16] baselines * [Linux / PostgreSQL 18] baselines * [Linux / PostgreSQL 17] baselines * [Linux / SQLite (both providers)] baselines * [Linux / Sybase ASE 16] baselines * [Linux / SQL Server 2025] baselines * [Linux / SAP HANA 2] baselines * [Linux / SQL Server EXTRAS] baselines --------- Co-authored-by: Azure Pipelines Bot <azp@linq2db.com> Co-authored-by: MaceWindu <MaceWindu@users.noreply.github.com>
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.
Fixes #5417