我对MongoDB非常陌生,但有我认为是非常简单的查询。无法在MongoDB中比较日期
我有一个从IProtein继承蛋白物件(是的,我命名很烂)
public interface IProtein
{
int Count { get; set; }
DateTime Date { get; set; }
}
我想返回从集合中FirstOrDefault
基于蛋白质对象的Date
场的日期比较Today
public IProtein GetProteinForDay(DateTime day)
{
var collection = _db.GetCollection<IProtein>(DB_COLLECTION);
var query = collection.AsQueryable<IProtein>()
.Where(p => p.Date == day.Date);
var protein = query.FirstOrDefault();
return protein;
}
不幸的是,我已经通过尝试匹配使用MongoDB的日期,所以许多不同的变化了(一些使用LINQ,有些没有),我已经完全多远时I g失去焦点ot与每一个。
这是我当前的代码,则返回错误Unable to determine the serialization information for the expression: p.Date
有什么不对我的查询(是的,它可能是一件很简单的),并实际上,我怎么用的MongoDB/Linq查询比较日期?
我想你可能某处[这里](https://stackoverflow.com/questions/40023067/unable-to找到答案-determine-the-serialization-information-for-expression-using-date) –
@AndrewWinterbotham我在这里通过这个和其他几个答案工作,但他们都没有工作。上面它是什么我问了这个问题 –