Conversation
5f9729f to
22ba473
Compare
There was a problem hiding this comment.
Pull request overview
Improves diagnostics when EF.Constant(), EF.Parameter() and EF.MultipleParameters() are used in contexts where EF Core disables parameterization (compiled queries and query filters), replacing a cryptic InvalidCastException with a targeted InvalidOperationException and adding coverage for the new behavior.
Changes:
- Add
_parameterize == falseguards inExpressionTreeFuncletizerforEF.Constantand the shared parameter handler (used byEF.Parameter/EF.MultipleParameters). - Introduce
CoreStrings.EFMethodNotSupportedInCompiledQueriesresource string for a clearer error message. - Add new tests for compiled queries and query filters to assert the new error.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.SqlServer.FunctionalTests/Query/NorthwindCompiledQuerySqlServerTest.cs | Adds required overrides so the SqlServer “all tests overridden” check includes the new compiled-query tests. |
| test/EFCore.Specification.Tests/Query/NorthwindCompiledQueryTestBase.cs | Adds tests asserting clearer exceptions for EF.Constant/EF.Parameter inside compiled queries. |
| test/EFCore.Specification.Tests/Query/AdHocQueryFiltersQueryTestBase.cs | Adds tests asserting clearer exceptions for EF.Constant/EF.Parameter inside query filters. |
| src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs | Throws a clearer exception when these EF helper methods are invoked while _parameterize is disabled. |
| src/EFCore/Properties/CoreStrings.resx | Adds the new localized error string template. |
| src/EFCore/Properties/CoreStrings.Designer.cs | Adds the generated accessor for the new resource string. |
Files not reviewed (1)
- src/EFCore/Properties/CoreStrings.Designer.cs: Language not supported
…r query filters When EF.Constant(), EF.Parameter(), or EF.MultipleParameters() are used inside compiled queries or query filters, throw a clear InvalidOperationException instead of a cryptic InvalidCastException. The check is in ExpressionTreeFuncletizer where parameterize is known to be false for these contexts. Closes #38151 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
22ba473 to
4bd878e
Compare
AndriySvyryd
approved these changes
Apr 23, 2026
Contributor
API review baseline changes for
|
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.
When
EF.Constant(),EF.Parameter(), orEF.MultipleParameters()are used inside compiled queries or query filters, a crypticInvalidCastExceptionwas thrown:This now throws a clear
InvalidOperationExceptionwith the message:The check is placed in
ExpressionTreeFuncletizerwhere theparameterizeflag is known to befalsefor compiled queries and query filters — the two contexts where these methods aren't supported.Changes
ExpressionTreeFuncletizer.cs— Added!_parameterizechecks inEF.ConstantandHandleParameter(used byEF.ParameterandMultipleParameters) handlersCoreStrings.resx/.Designer.cs— NewEFMethodNotSupportedInCompiledQueriesresource stringNorthwindCompiledQueryTestBase) + 2 for query filters (AdHocQueryFiltersQueryTestBase)Closes #38151