-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
I propose to allow Query.And() (and, probably, Query.Or()) to accept nulls, silently ignoring them (threating them as "match all").
Consider the following (pseudo)code:
bool condition = ...;
int data = ...;
int? data2= ...;
int? data3=...;
var query = condition ? Query.Null : Query.EQ("Value", data);
if (data2 != null)
query = Query.And(query, Query.Eq("Value2", (int)data2);
if (data2 != null)
query = Query.And(query, Query.Eq("Value2", (int)data3);
If nulls are allowed as arguments to Query.And, one can efficiently combine queries to create progressively more detailed requests. Currently, we have to resort to ugly things like Query.And() instead of Query.Null.
If silently ignoring nulls is not an option (though I think it's fine from a design standpoint), a Query.Any property containing an empty query would be most welcome.
P.S. I marked the issue as non-backward-breaking since I don't think that anyone relied on exception being thrown when null is passed into Query.And() or Query.Or().