Skip to content

Preserve implicit conversions in precompiled equality expressions - #39482

Closed
AndriySvyryd with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-query-precompilation-error
Closed

AndriySvyryd with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-query-precompilation-error

Conversation

Copilot AI commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Precompiling a query that compares a converter-backed custom property with a string parameter failed because the generated expression tree retained mismatched operand types.

  • Translation: Use Roslyn’s converted operand types for == and !=, preserving C# implicit conversions.
  • Regression coverage: Add a precompiled-query case for a custom type implicitly convertible to string and mapped with a value converter.
var name = "Some name";
var blog = await context.Blogs.FirstOrDefaultAsync(blog => blog.Name == name);

Copilot AI changed the title [WIP] Fix query precompilation error with convertible types Preserve implicit conversions in precompiled equality expressions Oct 30, 2026
Copilot AI requested a review from AndriySvyryd October 30, 2026 23:56
@AndriySvyryd
AndriySvyryd requested a lite review from Copilot October 31, 2026 00:16
@AndriySvyryd
AndriySvyryd deleted the copilot/fix-query-precompilation-error branch October 31, 2026 00:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical active finding indicates the inherited test will fail the SQL Server override guard before execution because its required provider override and SQL baseline are missing.

1 open issue
What changed in this PR

This pull request fixes precompiled-query translation for equality comparisons involving converter-backed custom properties and implicit conversions.

Changes:

  • Preserve Roslyn’s converted operand types for == and != expressions.
  • Add relational regression coverage for a custom type implicitly convertible to string.
  • Add supporting value-converter model and test data.
File Summary
src/​EFCore.Design/​Query/​Internal/​CSharpToLinqTranslator.cs Preserves implicit operand conversions when translating equality and inequality expressions.
test/​EFCore.Relational.Specification.Tests/​Query/​AdHocPrecompiledQueryRelationalTestBase.cs Adds regression coverage for comparing a converter-backed custom property with a string parameter. The inherited test requires a corresponding SQL Server override and AssertSql baseline.

Review effort: Lite

}

[Fact]
public virtual async Task Compare_converted_property_to_string()
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.

Checking equality of values with convertible types makes query precompilation fail

3 participants