MongoDB C# Nullable Datetime Query

.net, c#, datetime, mongodb, mongodb-.net-driver

Solution

You can compare the `DateTime?` to null instead of using `HasValue`:

Collection.AsQueryable<Candidate>(
    c => 
        c.IndexMetadata.Indexed == null || 
        c.IndexMetadata.Updated.Value > c.IndexMetadata.Indexed.Value).
    ToList();

Problem

I'm trying to query a over mongoDB and I get the following error: Unable to determine the serialization information for the expression: c.IndexMetadata.Indexed.HasValue. where Indexed is a nullable datetime my query is the following: ``` Collection.AsQueryable<Candidate>(c => !c.IndexMetadata.Indexed.HasValue || c.IndexMetadata.Updated.Value > c.IndexMetadata.Indexed.Value).ToList(); ``` both indexed and updated are type of nullable datetime I guess that's because there's no direct translation from HasValue into a mongo Query, any workaround?

Original source