以下LINQ2SQL代碼從表中最大日期是造成我很多頭痛,我希望有人能幫助嘗試使用LINQ2SQL
DateTime _maxRecordedDate = (from snapshot in _ctx.Usage_Snapshots
where snapshot.server_id == server_id
orderby snapshot.reported_on descending
select snapshot.reported_on).First().Value;
這個代碼在LinqPad和編譯罰款,但該項目運行時有一個「指定的方法是不受支持的」
如果我不使用的值,或將其丟我得到以下錯誤:
**
Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime'. An explicit conversion exists (are you missing a cast?)
**
經過大量搜索後,我發現問題源於使用ADO.NET數據服務。顯然他們使用Linq的有限子集,並且目前不可能使用Max,First等方法。僅使用First()的Bummmer – jdiaz 2009-05-23 23:33:31