-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: ASP NHibernate Criteria sorting/removing returned objects?
PostPosted: Tue Aug 03, 2010 1:51 pm 
Newbie

Joined: Tue Aug 03, 2010 1:39 pm
Posts: 1
Hello,

I'm trying to figure out a way to group, sort, and remove objects returned from the database using criteria expressions. What I have currently works fine, but i need the query more refined. Below gets units from the DB based on the criteria settings. What I need to add to this is : if the returned units have the same buildingID check to see if units types and Dates are the same, if yes select unit with lowest price and remove the rest under that building ID.

Here's the kicker, the list returned by this query can have multiple building id's. So can I achieve the above with NHibernate query's? If no do you have any ideas on how to help me?

Let me know if you need more clarification.

Code:
public static IList<MFISHMAN.WEB.DATA.Entities.Unit> getUnitSearchResults(string Price, string Type, string Date)
        {
            NHibernate.ISession currentSession = MFISHMAN.WEB.DATA.MfishmanApplication.GetCurrentSession();
            NHibernate.ICriteria criteria = currentSession.CreateCriteria(typeof(MFISHMAN.WEB.DATA.Entities.Unit));

            int iType = Convert.ToInt32(Type);
            int iDate = Convert.ToInt32(Date);
            string uDate = "";
            string uAvail = Date;
            string uPrice = Price;

            string[] strSplitArr = uPrice.Split(new Char[] { ',' });
           
            if (Date != "")
            {
                criteria.Add(NHibernate.Expression.Expression.Like("Date", iDate));
            }
            if (Price != "")
            {
                criteria.Add(NHibernate.Expression.Expression.Between("Price", Convert.ToString(strSplitArr[0]), Convert.ToString(strSplitArr[1])));
            }
            if (Type != "")
            {
                criteria.Add(NHibernate.Expression.Expression.Like("Type.TypeID", iType));
            }
            if (Date == "" && Price == "" && Type == "")
            {
            }           
           
            criteria.CreateCriteria("Type").AddOrder(NHibernate.Expression.Order.Asc("SortPriority"));
            criteria.AddOrder(NHibernate.Expression.Order.Asc("Price"));
            IList<MFISHMAN.WEB.DATA.Entities.Unit> units = criteria.SetResultTransformer(NHibernate.CriteriaUtil.DistinctRootEntity).List<MFISHMAN.WEB.DATA.Entities.Unit>();
           
            return units;


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.