tags:

views:

40

answers:

1

How I can lookup a specific date in Nhibernate?

I'm currently using this to lookup one day's order.

 ICriteria criteria = SessionManager.CurrentSession.CreateCriteria(typeof(Order))
            .Add(Expression.Between("DateCreated", date.Date.AddDays(-1), date.Date.AddDays(1)))
            .AddOrder(NHibernate.Criterion.Order.Desc("OrderID"));

I tried the following code, but they did bring the data for me.

Expression.Eq("DateCreated", date)

Expression.Like("DateCreated", date)

Note: The pass in date value will be like this 2010-04-03 00:00:00,

The actual date value in the database will be like this 2010-03-13 11:17:16.000

Can anyone let me know how to do this?

Many thanks.

+1  A: 

Since your database field has date and time information, querying for a single date will have to use between or greater than / less than. It's not clear from your question which query isn't working, but the second example using Expression will not work because the time portion does not match the time portion of the database record.

Jamie Ide