I have a table with a datetime field CreatedOn. I would like to fetch all records where the minute of the datetime field (CreatedOn) is between 31 and 59. I would like to get the NHibernate equivalent of
SELECT * FROM dbo.CL_M_Organization
WHERE DATEPART(mi,CreatedOn) BETWEEN 31 AND 59
The basic NHibernate query is
var result = NHSession.QueryOver<Organization>()
.Where(x=>x.CreatedOn < currentdatetime)
.List<Organization>()
.ToList();
The field CreatedOn is of type datetime.
Anyone please help...
If you're using an older version of NHibernate, you can use the
MinutePartextension method (found in theNHibernate.Criterionnamespace), along with theIsBetweenextension method:However, if you're using a newer version of NHibernate (>= 4), you should just use the
DateTime.Minuteproperty directly. NHibernate will understand what you're trying to do and translate it into SQL properly:Both of these will generate the following SQL: