Listato6b()

private Boolean Listato6b()
{
  // preparo i dati per il test
  Int32 custId;
  using (ISession session = NHSessionManager.GetSession())
  {
    session.CreateSQLQuery("delete from Orders").AddScalar("res", NHibernateUtil.Int32).UniqueResult();
    session.CreateSQLQuery("delete from Customer").AddScalar("res", NHibernateUtil.Int32).UniqueResult();
    
    Customer gianMaria = new Customer("Gian Maria", "Ricci");
    for (Int32 I = 0; I < 50; ++I)
      gianMaria.Orders.Add(new Order(DateTime.Now, I * 10.00f));
      
    custId = (Int32)session.Save(gianMaria);
    session.Flush();
  }
  
  using (ISession session = NHSessionManager.GetSession())
  {
    Customer gm = session.Get<Customer>(custId); 
    IList<Order> page;
    Int32 pageNum = 0;
    Int32 pageSize = 10;
    while ((page = session
                   .CreateFilter(gm.Orders, "select where Total > 100")
                   .SetFirstResult((pageNum++ * pageSize))
                   .SetMaxResults(pageSize)
                   .List<Order>()).Count > 0)
    {
      foreach (Order o in page)
        Console.WriteLine("Order {0} has total {1}", o.Id, o.Total);
    }
    return false;
  }
}