Details
-
Bug
-
Resolution: Fixed
-
Major - P3
-
None
Description
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.
Attachments
Issue Links
- 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...