Blogger Widgets
  • Sharing Photos using SignalR
  • TFS Extenstion - allows copy work items between projects
  • Displaying jquery progressbar with ajax call on a modal dialog
  • Managing windows services of a server via a website
  • Exploring technologies available to date. TechCipher is one place that any professional would like to visit, either to get an overview or to have better understanding.

Search This Blog

Wednesday, 19 October 2011

Using NHibernate Criteria with Join to get row count

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");

   ICriteria countCriteria = CriteriaTransformer.TransformToRowCount(crit);

   int rowCount = (int)countCriteria.UniqueResult();

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


Copyright © 2013 Template Doctor . Designed by Malith Madushanka - Cool Blogger Tutorials | Code by CBT | Images by by HQ Wallpapers