Here's the problem I'm trying to solve. I want to pass a date, then retrieve all itemorders that were picked on that date using NHibernate.
When I pass a orderPickDate to the method below, it never comes back with a result. I don't want to pass a date range, I just want to pass a single date, ignore the time, and if any itemOrders exist with that pick date return them.
public IList<ItemOrder> GetItemOrderByCriteria(int? itemNumber, int? warehouseNumber, DateTime? orderPickDate)
{
try
{
NHibernate.ICriteria criteria = NHibernateSession.CreateCriteria(typeof(Core.ItemOrder));
if (itemNumber.HasValue)
criteria.CreateCriteria("Item", "Item").Add(Expression.Eq("Item.ItemNumber", itemNumber.Value));
if (warehouseNumber.HasValue)
criteria.CreateCriteria("Warehouse", "Warehouse").Add(Expression.Eq("Warehouse.WarehouseNumber", warehouseNumber));
if (orderPickDate.HasValue)
criteria.Add(Expression.Eq("OrdPickDate", orderPickDate));
return criteria.List<Core.ItemOrder>();
}
catch (NHibernate.HibernateException he)
{
DataAccessException dae = new DataAccessException("NHibernate Exception", he);
throw dae;
}
}
Here's how this column is set up in the mapping:
<property name="OrdPickDate" column="ORD_PICK_DATE" type="date" not-null="true"/>
When I look at the sql nhibernate creates, it adds the following where clause(I passed it 12/1/2009 12:00:00 AM):
WHERE this_.ORD_PICK_DATE = '2009-12-01T00:00:00.00'
If I try to run the query in a db editor I get an error saying "ORA-01861: literal does not match format string." Should I be taking a different approach in creating my criteria?