-
Notifications
You must be signed in to change notification settings - Fork 934
Compile lambda for null access expressions #3157
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
Conversation
[Test] | ||
public void NullableNullValue() | ||
{ | ||
int? v = null; | ||
Expression<Func<int>> expression = () => v.Value; | ||
|
||
Assert.Throws<InvalidCastException>(() => GetValue(expression)); | ||
Assert.Throws<InvalidCastException>(() => expression.Compile().Invoke()); | ||
} |
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.
What about e => v.HasValue || e.SomeProperty = v.Value
? I wonder if it is supported or if it would throw.
(There is not much value in supporting this, excepted "feature parity" with linq-to-object: the .Value
is not needed in any way in such a query and can just be dropped. But still, it is better to know what how it behaves with NHibernate.)
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.
It throws on v.Value
evaluation:
NHibernate.HibernateException : Evaluation failure on null.Value
----> System.InvalidOperationException : Nullable object must have a value.
Maybe we shouldn't try to evaluate it in this context. But it's a different story not related to this PR.
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.
For sure, it would be beneficial if nullable.Value
works (with the SQL parameter becoming false, true, or NULL). The value of supporting this would be that users don't have to remember to adapt their expression specially.
No idea what the effort would be to support it though.
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.
it would be beneficial if
nullable.Value
works
Just to clarify things. This PR fixes regression caused by optimizations made in #2948, #2957. nullableNullParam.HasValue
or nullableNullParam.GetValueOrDefault()
works in 5.3 but throws on master (5.4-dev).
nullable.Value
fails the same in 5.3. So it's more like another feature request.
Fixes #3156