Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. NHibernate: getting the available row count while using maxResults

NHibernate: getting the available row count while using maxResults

Scheduled Pinned Locked Moved C#
questionjavaoracle
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    buchstaben
    wrote on last edited by
    #1

    Hi, I've done some hibernate work querying data from oracle. Since the return might be a very huge list of objects, I use the SetMaxResults() method.

    int maxDS = 1000;
    ISession session = //..
    ICriteria criteria = session.CreateCriteria(typeof(Trade));
    criteria.SetMaxResults(maxDS);
    AddCriterions(criteria); // I add some criterions in this method
    IList<Trade> trades = criteria.List<Trade>();

    How can I get the number of totally available objects (for my criterions) without disposing maxDS and loading them all? Thanks in advance.

    B 1 Reply Last reply
    0
    • B buchstaben

      Hi, I've done some hibernate work querying data from oracle. Since the return might be a very huge list of objects, I use the SetMaxResults() method.

      int maxDS = 1000;
      ISession session = //..
      ICriteria criteria = session.CreateCriteria(typeof(Trade));
      criteria.SetMaxResults(maxDS);
      AddCriterions(criteria); // I add some criterions in this method
      IList<Trade> trades = criteria.List<Trade>();

      How can I get the number of totally available objects (for my criterions) without disposing maxDS and loading them all? Thanks in advance.

      B Offline
      B Offline
      buchstaben
      wrote on last edited by
      #2

      I've found the solution:

      criteria.SetProjection(Projections.RowCount());
      int totalRecordsFound = (int)criteria.UniqueResult();

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups