Skip to content

Conversation

@roji
Copy link
Member

@roji roji commented Nov 25, 2025

Backports #37233
Closes #37178

Description

10.0 contained various bug fixes to EF's DefaultIfEmpty() LINQ operator translation. One of these bugfixes required making changes to how COALESCE() is added for non-nullable value types, where we need to return the CLR default (e.g. zero for int) rather than NULL. Unfortunately, to determine whether the return value is a non-nullable value type, an incorrect type was consulted in the SQL tree, which indicates a non-nullable value type even when the returned value is in fact a nullable value type.

Customer impact

In cases where DefaultIfEmpty() is used over a nullable value type, NULL is not returned as expected, but rather than CLR default.

var items = await context.Products
    .Select(x => x.NullableInt)
    .DefaultIfEmpty()
    .ToListAsync();

This is a data corruption bug, indicating that there's data in the database (zero), where in fact there's no data (and NULL should be returned).

How found

Customer reported on 10.0.0

Regression

Yes, from 9.0.

Testing

Added.

Risk

Low, very targeted fix (most code in this PR only flows information in, actual behavioral change is a one-liner). Quirk added.

@roji roji changed the title Correct COALESCE logic for DefaultIfEmpty (#37233) [release/10.0] Correct COALESCE logic for DefaultIfEmpty (#37233) Nov 25, 2025
@roji roji marked this pull request as ready for review November 25, 2025 15:09
@roji roji requested a review from a team as a code owner November 25, 2025 15:09
@roji roji requested review from artl93 and cincuranet November 25, 2025 15:09
Copy link
Member

@artl93 artl93 left a comment

Choose a reason for hiding this comment

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

Customer reported, regression, data corruption.

@rbhanda rbhanda added this to the 10.0.2 milestone Nov 25, 2025
@roji roji merged commit 2d68ad0 into dotnet:release/10.0 Nov 25, 2025
7 checks passed
@roji roji deleted the DefaultIfEmptyCoalesce10 branch November 25, 2025 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants