-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement nullability simplification for COLLATE
and AT TIME ZONE
#34263
Conversation
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(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 ofAtTimeZone
is 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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] NULL
to handleCOLLATE
andAT TIME ZONE
.Closes #34295