-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 1.7.1
-
Component/s: Linq
-
None
String.IsNullOrEmpty(x.S) expands to
"$or" : [{ "S" :
},
{ "S" : "" }]
If a field has BsonIgnoreIfNull, it should also test
{ "S" : null }Here's a test illustrating this:
public class WithString { [BsonIgnoreIfNull] public string S { get; set; } } [Test] public void StringIsNullOrEmptyShouldTestIgnoredNulls() { var a = new WithString() {S = "ooo"}; var b = new WithString() {S = ""}; var c = new WithString() { }; collection.Insert(a); collection.Insert(b); collection.Insert(c); var query = from t in collection.AsQueryable() where string.IsNullOrEmpty(t.S) select t; var translated = MongoQueryTranslator.Translate(query); var mongoQuery = ((SelectQuery)translated).BuildQuery(); Debug.WriteLine(mongoQuery.ToString()); var results = query.ToList(); Assert.That(results.Count, Is.EqualTo(2)); }