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);
精彩评论