Repository navigation
Throw EF Core's non-composable SQL error for FromSql/SqlQuery over CALL and other non-query statements - #468
Merged
renemadsen merged 1 commit intoOct 16, 2026
Conversation
MySqlQuerySqlGenerator overrode CheckComposableSql with an empty method,
so composing over FromSql/SqlQuery with SQL such as CALL was sent to the
server as "SELECT ... FROM (CALL ...) AS t" and failed with a syntax
error. With EF Core 10 this also affects a plain FromSql("CALL ...") on
entities with a JSON-mapped member, which EF Core always wraps.
The override predates EF Core accepting WITH (7.0). Use the base check
again, and additionally accept the forms MySQL and MariaDB can compose
over: parenthesized query expressions, TABLE and VALUES.
Remove the FromSqlSprocQueryMySqlTest overrides that asserted
MySqlException; the EF Core specification tests assert the
non-composable InvalidOperationException.
See PomeloFoundation#1543 and PomeloFoundation#2035.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Problem
When a LINQ query composes over raw SQL that cannot be used as a derived table, the provider sends it to the server wrapped in a subquery anyway:
The server answers with
MySqlException: You have an error in your SQL syntax … near 'CALL …'. Every other relational provider throwsInvalidOperationExceptionwithRelationalStrings.FromSqlNonComposablebefore a command is sent, which tells the user what is wrong and how to fix it (AsEnumerable()).This is more visible with EF Core 10. An entity that has a JSON-mapped complex or owned type is never treated as a non-composed
FromSqlquery (EF Core limitation: the JSON projection is not a plain column), so even a bareFromSqlRaw("CALL …").ToList()gets wrapped and fails with the syntax error.Root cause
MySqlQuerySqlGeneratoroverridesCheckComposableSqlwith an empty body. The override was added in 2021 (PomeloFoundation PR 1539) because EF Core rejectedWITHat the time. EF Core has acceptedWITHsince 7.0 (dotnet/efcore#26471), and PomeloFoundation issue 1543 has tracked removing the override since then.Change
CheckComposableSqloverride with aCheckComposableSqlTrimmedoverride that defers to the base implementation (SELECT,WITH) and additionally accepts the forms MySQL and MariaDB can compose over but EF Core does not know about: a parenthesized query expression,TABLE …andVALUES …. This keeps raw SQL that works today working.FromSqlSprocQueryMySqlTestthat assertedMySqlException. The EF Core specification tests they replaced assertInvalidOperationExceptionwith the non-composable message, which is now what happens.MySqlFromSqlComposabilityTest(8 tests).Tests
New, in
test/EFCore.MySql.Tests/Query/MySqlFromSqlComposabilityTest.cs:Stored_procedure_call_without_composition_worksComposing_over_stored_procedure_call_throws_non_composableMySqlException)Composing_over_non_query_statement_throws_non_composableMySqlException)Composing_over_select_with_leading_comments_worksComposing_over_common_table_expression_worksComposing_over_parenthesized_query_expression_worksComposing_over_table_statement_works(MySQL 8.0.19+)Composing_over_values_statement_works(MySQL 8.0.19+)Results on MySQL 8.4.10, Windows, .NET SDK 10.0.101:
EFCore.MySql.TestsEFCore.MySql.FunctionalTests, filterFromSql|SqlQuery|SqlExecutorEFCore.MySql.IntegrationTestsEFCore.MySql.FunctionalTests, fullmaster)I have no MariaDB instance locally, so MariaDB coverage relies on CI here.
Compatibility
InvalidOperationExceptioninstead ofMySqlException. Both are failures; code that caughtMySqlExceptionfor this case would need to catch the new type. No query that succeeded before fails now, as far as the test suite and the added guard tests show.TABLEandVALUEStests are gated onServerVersionSupport.ValuesWithRows, so they skip on MariaDB and on MySQL before 8.0.19.Related
TABLEandVALUESforms composable)Remaining limitations
FromSql("CALL …")on an entity with a JSON-mapped member still cannot work; it now fails with the EF Core message instead of a syntax error. Fixing that needs a change in EF Core'sIsNonComposedFromSql.🤖 Generated with Claude Code