Search code examples
linqnullablemongodb-.net-driver

MongoDB C# Linq driver with nullable types


I am using mongodb c# driver and tried the following query

collection.AsQueryable().Where(x => x.IsArchived.GetValueOrDefault())

where IsArchived is of type bool? (nullable).

I get the following runtime error:

Unsupported where clause: x.IsArchived.GetValueOrDefault().

Does anybody know how I can query nullable types?


Solution

  • i found out a workaround, though it is not very nice:

    collection.AsQueryable().Where(x => x.IsArchived ?? false)