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.  [ 3 posts ] 
Author Message
 Post subject: How to use CountProjection ?
PostPosted: Fri Jul 04, 2008 10:06 am 
Beginner
Beginner

Joined: Fri Feb 29, 2008 9:36 am
Posts: 40
Hi,

Today, to get a number of row on a "criteria", I use:

Code:
return session.CreateSQLQuery("select count(*) from users where id_profile = :idprofile")
.SetParameter("idprofile", (Int32)value, Hibernate.NHibernateUtil.Int32)
.UniqueResult<System.Int64>();


I have found the CountProjection class.

Is it a better way to get the count ?

Problem, if I code:

NHibernate.Expression.CountProjection count = new CountProjection();

I get an error on protection level for
NHibernate.Expression.CountProjection.CountProjection(string)

How to use this class please ?

Papy!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 11:08 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Try this:

Code:
session.CreateCriteria(typeof(Users))
    .Add(Expression.Eq("IdProfile", value)
    .SetProjections(Projections.RowCount()).UniqueResult<long>();

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 11:25 am 
Beginner
Beginner

Joined: Fri Feb 29, 2008 9:36 am
Posts: 40
Thanks a lot ! you're great !


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

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.