Implement nullability simplification for COLLATE and AT TIME ZONE#34263
Implement nullability simplification for COLLATE and AT TIME ZONE#34263roji merged 6 commits intodotnet:mainfrom
COLLATE and AT TIME ZONE#34263Conversation
It now handles `COLLATE` and `AT TIME ZONE`.
|
This was born out of @roji's comment here: #34127 (comment) Should I simply open a new issue covering |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
The Helix failure(s) is weird: |
|
I will need some guidance to reproduce the error locally. |
| select e.Id).ToList(); | ||
|
|
||
| var actual = (from e in context.Set<OperatorEntityNullableDateTimeOffset>() | ||
| where !((DateTimeOffset?)EF.Functions.AtTimeZone(e.Value.Value, "UTC")).HasValue |
There was a problem hiding this comment.
(unrelated to this PR)
this syntax looks convoluted and is fragile when combined with other operations
I was able to invoke EF.Functions.AtTimeZone on a DateTimeOffset? with .Value, but I was unable to convince the compiler that comparing its result to null was reasonable, even after a cast.
Specifically, the compiler rejects:
EF.Functions.AtTimeZone(e.Value.Value, "UTC") == null(which looks like the most natural way to perform this check in an expression, but is forbidden because on the C# side the result ofAtTimeZoneis a non-nullable value type)((DateTimeOffset?)EF.Functions.AtTimeZone(e.Value.Value, "UTC")) == null
💔
EDIT: mentioned that it is not a problem in the commits (but I would still love to express this more cleanly 😇 )
There was a problem hiding this comment.
you can use pragma to work around compiler block:
var actual = (from e in context.Set<OperatorEntityNullableDateTimeOffset>()
#pragma warning disable CS8073 // The result of the expression is always the same since a value of this type is never equal to 'null'
where EF.Functions.AtTimeZone(e.Value.Value, "UTC") == null
#pragma warning restore CS8073 // The result of the expression is always the same since a value of this type is never equal to 'null'
select e.Id).ToList();
Given that it reproduces only on Helix machines and not the rest, makes me believe that it's not going to be easy to reproduce it locally. :( |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@ranma42 Seems to be OK now. Phew. |
Instead of working around the compiler by casting the expression, simply suppress the compiler warning. Suggested by @maumar.
This changeset extends the simplification for
IS [NOT] NULLto handleCOLLATEandAT TIME ZONE.Closes #34295