我對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我在這裏通過這個和其他幾個答案工作,但他們都沒有工作。上面它是什麼我問了這個問題 –