Skip to content

[release/10.0] Handle MemoryExtensions.Min/Max Span overloads introduced in .NET 11#38618

Open
AndriySvyryd with Copilot wants to merge 4 commits into
release/10.0from
copilot/handle-new-min-max-span-overloads
Open

[release/10.0] Handle MemoryExtensions.Min/Max Span overloads introduced in .NET 11#38618
AndriySvyryd with Copilot wants to merge 4 commits into
release/10.0from
copilot/handle-new-min-max-span-overloads

Conversation

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #38508

Description
.NET 11 adds MemoryExtensions.Min(ReadOnlySpan<T>) and MemoryExtensions.Max(ReadOnlySpan<T>). Due to first-class spans overload resolution, new[] { 30, x }.Min() in a query expression tree will resolve to these Span-based overloads instead of Enumerable.Min.

Customer impact
Affected queries will throw an exception at runtime

How found
Found during .NET 11 SDK upgrade.

Regression
No.

Testing
Tests added.

Risk
Low. It's a purely additive change.

Copilot AI and others added 2 commits July 13, 2026 21:12
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Handle the new Min/Max span overloads Handle MemoryExtensions.Min/Max Span overloads introduced in .NET 11 Jul 13, 2026
Copilot AI requested a review from AndriySvyryd July 13, 2026 21:17
@AndriySvyryd AndriySvyryd marked this pull request as ready for review July 13, 2026 23:44
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner July 13, 2026 23:44
Copilot AI review requested due to automatic review settings July 13, 2026 23:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates EF Core’s query expression processing to handle the new .NET 11 MemoryExtensions.Min/Max(ReadOnlySpan<T>) overloads that can be selected by first-class span overload resolution, rewriting them to Enumerable.Min/Max(IEnumerable<T>) so translation can proceed without ref-structs in expression trees.

Changes:

  • Extend ExpressionTreeFuncletizer’s existing MemoryExtensions rewrite logic to also rewrite Min and Max span overloads to Enumerable.Min/Max.
  • Add .NET 11+ spec tests for Min_on_MemoryExtensions and Max_on_MemoryExtensions.
  • Add provider-specific SQL assertions for the new tests across SQLite, SQL Server variants, and Cosmos.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs Rewrites MemoryExtensions.Min/Max(span) calls to Enumerable.Min/Max to avoid ref-structs in expression trees.
test/EFCore.Specification.Tests/Query/PrimitiveCollectionsQueryTestBase.cs Adds new .NET 11+ baseline queries for Min/Max on MemoryExtensions.
test/EFCore.Sqlite.FunctionalTests/Query/PrimitiveCollectionsQuerySqliteTest.cs Adds .NET 11+ SQL assertions for min/max translation.
test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs Adds .NET 11+ SQL assertions for MIN/MAX translation (VALUES-based).
test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServer160Test.cs Adds .NET 11+ SQL assertions using LEAST/GREATEST translation.
test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerJsonTypeTest.cs Adds .NET 11+ SQL assertions using LEAST/GREATEST translation for JSON type mapping scenarios.
test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQueryOldSqlServerTest.cs Adds .NET 11+ SQL assertions for compatibility-level-limited translation (VALUES-based).
test/EFCore.Cosmos.FunctionalTests/Query/PrimitiveCollectionsQueryCosmosTest.cs Adds .NET 11+ Cosmos SQL assertions for MIN/MAX over inline arrays.

Comment thread src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 14, 2026 00:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

Comment thread src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs
Copilot AI requested a review from AndriySvyryd July 14, 2026 01:59
@AndriySvyryd AndriySvyryd changed the title Handle MemoryExtensions.Min/Max Span overloads introduced in .NET 11 [release/10.0] Handle MemoryExtensions.Min/Max Span overloads introduced in .NET 11 Jul 14, 2026
@AndriySvyryd AndriySvyryd requested a review from cincuranet July 14, 2026 02:31
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.

Handle the new Min/Max Span overloads

3 participants