Nhibernate

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
Ken
Ensign (ENS)
Ensign (ENS)
Posts: 9
Joined: Mon Sep 03, 2012 1:17 am

Nhibernate

Post by Ken » Wed Apr 10, 2013 12:03 am

I have two questions related to Nhibernate.

1. how to pass sortexpression to Nhibernate criteria . For instance ,I want to sort by product.createddate desc.

Code: Select all

ICriteria criteria = NHibernateHelper.CreateCriteria<Product>(maximumRows, startRowIndex, sortExpression);
        criteria.Add(Restrictions.Eq("VisibilityId", (byte)CatalogVisibility.Public));
what value I should give to sortExpression. CreatedDate.Desc?

2. I want to get the lastest created time from product table and assign that to a variable. How can I do that with Nhibernate?

Thanks

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Nhibernate

Post by mazhar » Tue Apr 16, 2013 2:33 am

Ken wrote:I have two questions related to Nhibernate.

1. how to pass sortexpression to Nhibernate criteria . For instance ,I want to sort by product.createddate desc.

Code: Select all

ICriteria criteria = NHibernateHelper.CreateCriteria<Product>(maximumRows, startRowIndex, sortExpression);
        criteria.Add(Restrictions.Eq("VisibilityId", (byte)CatalogVisibility.Public));
what value I should give to sortExpression. CreatedDate.Desc?

2. I want to get the lastest created time from product table and assign that to a variable. How can I do that with Nhibernate?

Thanks
1- sortExpression => CreatedDate DESC
First property name then a space and finally ASC(optional) or DESC for sort direction

2- Try somthing like this

Code: Select all

DateTime createdDate = NHibernateHelper.CreateCriteria<Product>(1, 0, "CreatedDate DESC")
                .SetProjection(NHibernate.Criterion.Projections.Property("CreatedDate"))
                .UniqueResult<DateTime>();

Post Reply