开发者

Compare datetime property to certain date via HQL (.Net)

I have problems comparing the datetime property of objects and when trying to compare to a given date. For example, I tried

 IQuery query1 = session.Cr开发者_运维百科eateQuery(String.Format(
            @"Select s.Id  
            From InventoryProductStateItem s
            Where s.ValidFrom = " + stateItem.ValidFrom));

but get an exception "Incorrect syntax".


Dates can be compared by passing a parameter to the query:

IQuery query1 = session.CreateQuery(String.Format(
            @"Select s.Id  
            From InventoryProductStateItem s
            Where s.ValidFrom = :stateDate)")).SetParameter("stateDate", state.ValidFrom);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜