I have following database table ‘Date’:
DateId Date
1 08/05/2012
2 08/01/2012
3 08/25/2012
4 08/15/2012
5 08/22/2012
.....
To get most recent date i am using following expression:
var recentDate = db.Date.OrderByDescending(d => d.Date).FirstOrDefault();
How can i use recentDate to get previous date or next date using lambda expressions?
When i try to use latestDate i get an error saying:
operator > cannot be applied to operands of type 'System.DateTime' and 'App.Models.Date
this is what i am trying for previous date:
var previous date = top10Date.Where(d => d.Date > latestDate).OrderBy(d => d.Date).FirstOrDefault();
is above expression right? how can i make this work?
You are trying to compare DateTime to App.Models.Date, which the compiler does not know how to compare.
You are probably trying to do the following: