You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our nullability processor has logic that identifies string concatenation, and if one side is nullable, adds a COALESCE to an empty string. IIUC this is inconsistent with the rest of EF's behavior: we do not add coalesce-to-zero for nullable arithmetic columns, and we don't add COALESCE nodes to function arguments when a null would make that function return null.
This is also the source of npgsql/efcore.pg#2889 on the PG side: we use string concatenation to generate an interval expression: CAST(t."Diff"::text || ' days' AS interval. But because the Diff column is nullable, SqlNullabilityProcessor adds the coalesce it to CAST(COALESCE(t."Diff"::text, '') || ' days' AS interval, causing mangled SQL (an empty string is bad here, just having the null would work as expected).
I'm not sure there's a specific reason we need to have special null protection for string concatenation and for nothing else..
Activity
maumar commentedon Jun 9, 2025
introduced as fix to #3836
roji commentedon Jun 9, 2025
I looked a little bit into this, an in C# itself the concatenation operator provides coalesce-to-empty-string behavior:
The same doesn't apply e.g. for integer addition:
So EF seems to be doing the right thing here, i.e. replicating C# behavior, even if that C# behavior could be considered somewhat inconsistent:
I'll go ahead and close this as the expected behavior and try to think of a creative way to work around npgsql/efcore.pg#2889.