开发者

NHibernate: how to do lookup a specific date in Nhibernate

开发者 https://www.devze.com 2022-12-25 19:02 出处:网络
How I can lookup a specific date in Nhibernate? I\'m currently using this to lookup one day\'s order. ICriteria criteria = Sess开发者_StackOverflow中文版ionManager.CurrentSession.CreateCriteria(typ

How I can lookup a specific date in Nhibernate?

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

 ICriteria criteria = Sess开发者_StackOverflow中文版ionManager.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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消