It depends on the LINQ provider. I'm not sure if NHibernate LINQ supports the syntax item.SomeDateProperty.Date == x
, and I doubt it is. But you can make your own extension method as follows:
public static IQueryable<T> FilterByDate(this IQueryable<T> This, Expression<Func<T, DateTime>> getProperty, DateTime date) { DateTime from = day.Date; DateTime to = day.Date.AddDays(1); return This.Where(x=> Expression.And( Expression.GreaterThan(getProperty, Expression.Variable(from)), Expression.LessThan(getProperty, Expression.Variable(to))); }
This is NOT going to build like it is now, I was just trying to give you an idea of ββwhat to do.
Then you can use it like this:
var result = repository.Table.FilterByDate(x=>x.MyDate, new DateTime(2012, 6,6));
Mr. TA source share