MongoDb C# 驱动程序在 DateTime 比较中抛出序列化错误

MongoDb C# driver throwing Serialization error in DateTime comparison

我正在为 MongoDb 使用 C# 驱动程序。我有一个非常简单的 'find' 查询:

var cursor = PortalContext.Users.Find(user => DateTime.Now > user.UpdatedDate);
return cursor.ToListAsync();

抛出异常:

Message: "An error has occurred."
ExceptionMessage: "Unsupported filter: (8/13/2015 12:03:44 PM > Serialization(UpdatedDate))."
ExceptionType: "System.ArgumentException"
StackTrace: " at MongoDB.Driver.Linq.Translators.PredicateTranslator.BuildFilter(Expression expression) at ...

尝试重新排列您的 Find,使常量 (DateTime.Now) 位于右侧,行得通吗?

var cursor = PortalContext.Users.Find(user => user.UpdatedDate < DateTime.Now);
return cursor.ToListAsync();

1.x 驱动程序 (CSHARP-431) 中存在错误,驱动程序无法处理常量位于左侧的这种情况。它在很久以前就已修复,但这个问题可能是它的倒退。