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: Set alias on object when using conjunction
PostPosted: Mon Jul 07, 2008 8:29 am 
Beginner
Beginner

Joined: Mon Jan 14, 2008 10:58 am
Posts: 24
Hi,
I have problem to set an expression to an alias when using conjunction.
I'm using this code:
Code:
public IList<T> GetObjects(ICriterion[] criterions, int skip, int take, out int recordCount)
        {
            try
            {
                Conjunction con = Expression.Conjunction();
               
                if (criterions != null)
                {
                    foreach (ICriterion c in criterions)
                    {
                        if (c != null)
                            con.Add(c);
                    }
                }

                int count = (int)NHibernateHelper.GetCurrentSession().CreateCriteria(typeof(T))
                .Add(con)
                .SetProjection(Projections.RowCount()).UniqueResult();
                recordCount = count;

                ICriteria criteria = NHibernateHelper.GetCurrentSession().CreateCriteria(typeof(T));
                criteria.Add(con);

                if (aliasParams != null)
                {
                    foreach (AliasParam ap in aliasParams)
                        criteria.CreateAlias(ap.AssiciationPath, ap.Alias);
                }

                if (skip > 0)
                    criteria.SetFirstResult(skip);

                if (take > 0)
                    criteria.SetMaxResults(take);

                return criteria.List<T>();
            }
            catch (Exception)
            {
                throw;
            }
        }

Code:
private void BindRepeater()
        {
            ForumThreadDao.AliasParams.Add(new AliasParam("Forum", "f"));
            ICriterion[] cri = {
                   Expression.Eq("f.IsEnabled", true),
                   Expression.Eq("f.SiteLanguage", UserInfo.CurrentLanguage)
                               };
            int recordCount;

            ForumRepeater.DataSource = ForumThreadDao.GetObjects(cri, 0, 10, out recordCount);
            ForumRepeater.DataBind();

        }


The problem is that the criterion is set before the alias and because of that I'm getting:
could not resolve property: f of: Entities.ForumThread
How can I change the code?


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.