views:

37

answers:

1

Hello, 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.CreateQuery(String.Format(
            @"Select s.Id  
            From InventoryProductStateItem s
            Where s.ValidFrom = " + stateItem.ValidFrom));

but get an exception "Incorrect syntax".

A: 

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);
Jan-Frederik Carl