Daoming,
That solution is off by one: it will match items with DateCreated == date +
1 at 0:00.

The cleanest solution is, as Fabio mentioned, NOT storing a time there if
what you work with is a date.
If you DO need the time, but just not in this case, you could use this:

.Add(Restrictions.Eq(Projections.SqlFunction("date", NHibernateUtil.Date,
Projections.Property("DateCreated")), date))

It does look ugly in Criteria*... it's a little nicer in HQL:

from Order order where date(order.DateCreated) = :date

Or even better in Linq:

session.Linq<Order>().Where(o => o.DateCreated.Date == date);

   Diego

*: maybe there's a better way to write that, but I'm not a Criteria expert.


On Mon, Apr 5, 2010 at 07:28, Daoming Yang <[email protected]>wrote:

> Thank you Jason. I have resolved my problem by using your suggestion.
>
> .Add(Expression.Between("DateCreated", date, date.Date.AddDays(1)))
>
> HI Fabio,
>
> *DateCreated *is a DateTime data type column in the order table, it
> presents when this order is created.
>
> Here is my mapping.
>
> <property name="DateCreated" column="DateCreated" />
>
>
> Daoming
>
>
>
> On 5 April 2010 04:29, Fabio Maulo <[email protected]> wrote:
>
>> 2010/4/4 Jason Dentler <[email protected]>
>>
>> Could be... In my world, everything is date & time, so I assume the same
>>> for everyone else.
>>
>>
>> In my world a Date is a Date and a moment/timestamp is another thing.
>> So when I compare a Date with another Date I'm not comparing a range...
>> Btw... I'll leave you in your world.
>> C u.
>>
>> --
>> Fabio Maulo
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "nhusers" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<nhusers%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/nhusers?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to