Google for lot of places for using Criteria object having joins and get rowcount either by using Projections.RowCount or CriteriaTransformer.TransformToRowCount. Now I have started looking into NHibernate source code which does also provides with examples of how to use it.
So the example is as follows :-
public void TransformToRowCountTest()
{
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
ICriteria crit = s.CreateCriteria(typeof(Student));
ICriteria subCriterium = crit.CreateCriteria("PreferredCourse");
subCriterium.Add(Property.ForName("CourseCode").Eq("MCSD"));
ICriteria countCriteria = CriteriaTransformer.TransformToRowCount(crit);
int rowCount = (int)countCriteria.UniqueResult();
t.Rollback();
s.Close();
}
This does the job of counting number of students who are enrolled for a course with code "MCSD"
The real danger is not that computers will begin to think like men, but that men will begin to think like computers. ~Sydney J. Harris
Great Article
ReplyDeleteASP.NET MVC Training
Online MVC Training
Online MVC Training India
Dot Net Training in Chennai
.Net Online Training
.net training online
Dot Net Online Training
C# Training