Search code examples
c#.netmongodbmongodb-.net-drivermongodb-csharp-2.0

MongoDb c# driver 2.0 BsonNull usage


I have isDeleted Nullable property in Profile class.

Builders<Profile>.Filter.Eq(p => p.IsDeleted, BsonNull.Value)

But the following code raised next compilation error:

Error 11    Cannot convert lambda expression to type 
'MongoDB.Driver.FieldDefinition<MongoDB.DataTypes.Profile,MongoDB.Bson.BsonNull>' 
because it is not a delegate type   

How to implement a null-check ?


Solution

  • If IsDeleted is nullable, you can just use a simple null instead of BsonNull.Value when you query:

    Builders<Profile>.Filter.Eq(p => p.IsDeleted, null)