In my Linq query I have the following :
.Where(x => x.dtt_ref_no == dtt_ref)
where x.dtt_ref_no is a nullable int
and dtt_ref is of type int.
What is the correct way to compare these two values?
Your code works as it is, if you use ==
on a int?
and an int
it will return false
if the nullable doesn't contain a value. So it's the same as if you'd write:
.Where(x => x.dtt_ref_no.HasValue && x.dtt_ref_no.Value == dtt_ref)
It's the same behaviour as Nullable<T>.Equals
because the int
will be converted to an int?
implicitly on comparison.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With