所以我有这个枚举
public enum JobStatus
{
Created = 0,
Assigning = 1,
Assigned = 2,
Started = 3,
Finished = 4
}
在这个界面
public interface IJob
{
Guid Id { get; set; }
JobStatus Status { get; set; }
bool IsFaulted { get; set; }
string ErrorMessage { get; set; }
}
我将其中一个人放入数据库中,一切正常。这就是它的样子。
{ "_id" : { "$uuid" : "4e5002b6-3c80-b497-4a33-46b0ea5a39bf"}
, "_t" : "MyJobObject"
, "Status" : 0
, "IsFaulted" : false
, "ErrorMessage" : null
, "Location" : "overthere"}
然后,当我尝试使用此代码获取一个时
Database.GetCollection<IJob>("Jobs").AsQueryable().FirstOrDefault(x=>x.Status == JobStatus.Created);
这会引发异常
Unable to determine the serialization information for the expression: jobs.Status.
at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.GetSerializationInfo(Expression node, Dictionary`2 serializationInfoCache)
at MongoDB.Driver.Linq.Utils.BsonSerializationInfoHelper.GetSerializationInfo(Expression node)
at MongoDB.Driver.Linq.PredicateTranslator.BuildComparisonQuery(Expression variableExpression, ExpressionType operatorType, ConstantExpression constantExpression)
at MongoDB.Driver.Linq.PredicateTranslator.BuildComparisonQuery(BinaryExpression binaryExpression)
at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery(Expression expression)
at MongoDB.Driver.Linq.SelectQuery.BuildQuery()
at MongoDB.Driver.Linq.SelectQuery.Execute()
at MongoDB.Driver.Linq.MongoQueryProvider.Execute(Expression expression)
at MongoDB.Driver.Linq.MongoQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
我的第一次尝试没有将枚举分配给整数,这产生了相同的结果。我在两台不同的机器上看到了这一点,两个全新安装的 MongoDb,一个在 Windows 上,一个在 Ubuntu 12.04 上。
不知道该怎么做,有什么想法吗?