I would like to fetch all records from particular day, no matter what time is associated with those records. So far I have method like this:
public IQueryable<Record> QueryByDay(DateTime day)
{
DateTime from = day.Date;
DateTime to = day.Date.AddDays(1);
return repository.Table
.Where(t => t.MyDate >= from && t.MyDate < to);
}
But in linq-to-object we can do (assuming Table is now some collection):
public IEnumerable<Record> QueryByDay(DateTime day)
{
return repository.Table
.Where(t => t.MyDate.Date == day.Date);
}
Which is obviously more readable and feels more clean. I was wondering if there is better way to write the first method using database storage and nhibernate?