LIKE query for DateTime in NHibernate
Posted
by Anry
on Stack Overflow
See other posts from Stack Overflow
or by Anry
Published on 2010-04-14T17:07:27Z
Indexed on
2010/04/14
17:23 UTC
Read the original article
Hit count: 331
nhibernate
|criteria
For a column of type varchar I could write such a query:
public IList<Order> GetByName(string orderName)
{
using (ISession session = NHibernateHelper.OpenSession())
{
return session.CreateCriteria<Order>().
Add(Restrictions.Like("Name", string.Format("%{0}%", orderName))).
List<Order>();
}
}
How do I write a similar LIKE-query for a column that has type datetime?
public IList<Order> GetByDateTime(DateTime dateTime)
{
using (ISession session = NHibernateHelper.OpenSession())
{
return //LIKE-query
}
}
That is, if the method is passed the date and part-time (eg "25.03.2010 19"), then displays all orders are carried out in this period of time.
© Stack Overflow or respective owner