-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Linq
Driver version 2.8.2
string.isNullOrEmpty utilizes a test for null equality using
"$or":[ { "$eq":[ "$someField", null ] }, { "$eq":[ "$someField", "" ] } ] }
However, if the field is not present, the null equality operation returns false.
The null coalescing operator (??) on the other hand does work with both nulls and non-existing fields, and uses the $ifNull operation rather than equality.
"Url":{ "$ifNull":[ "$shopUrl", "$typeUrl" ] },
It seems that $ifNull would be a better operation to use in the composed string.IsNullOrEmpty() method.
Without this, we have to resort to strange expressions like:
isExternalUrl = string.IsNullOrEmpty((pt.ShopUrl ?? "")),
If I don't use the null coalescing operator in that example, the evaluation will return false when the field does not exist.
- is related to
-
CSHARP-4057 LinqV3 Null Coalescing operator with empty string expression results in "Cannot find serializer for null"
- Closed
- mentioned in
-
Page Loading...