Listato4()

private static void Listato4()
{
  // 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);
    Int32 count = gm.Orders.Count;
  }
}