DateTime.Date in .where() statement

Topics: Writing modules
Apr 15, 2013 at 6:37 AM
Edited Apr 15, 2013 at 3:15 PM
I have this code:
var date = DateTime.Now;

var records = viewRepository.Table;
records.Where(v => v.ViewStart.Date == date.Date);
This errors but this works
records.Where(v => v.ViewStart == date);
I know absolutely nothing about NHibernate and that stuff, but I assume it doesn't support the System.DateTime stuff. Or something.

Anyway, so I kinda need to be able to access the DateTime properties so I can get the right stuff from the database. Any advice on what I should look at to do this? I had a quick look and I saw some stuff about using SQL and HQL, are these the paths to go down?

Cheers for any insights


I was too tired to think straight at the ungodly hour I posted this question. A colleague pointed out a simple solution
public Expression<Func<ViewRecord, bool>> EqualDatesPredicate(DateTime date) 
      return v => v.ViewStart > date.Date && v.ViewStart < date.Date.AddDays(1);
Obviously not ideal to have to constantly work around the lack of DateTime properties but hey, it works