Listato3()
private static void Listato3() { // preparo i dati per il test 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 andreaMarzilli = new Customer("Andrea", "Marzilli"); Order order0 = new Order(DateTime.Now.AddDays(-2), 999.00f); andreaMarzilli.Orders.Add(order0); session.Save(andreaMarzilli); Customer gianMaria = new Customer("Gian Maria", "Ricci"); Order order1 = new Order(DateTime.Now, 10.00f); Order order2 = new Order(DateTime.Now, 20.00f); gianMaria.Orders.Add(order1); gianMaria.Orders.Add(order2); session.Save(gianMaria); session.Flush(); } // Sposto un ordine da un cliente ad un altro using (ISession session = NHSessionManager.GetSession()) { Customer gm = session.CreateQuery("select c from Customer c where c.Name = 'Gian Maria'") .UniqueResult<Customer>(); Customer am = session.CreateQuery("select c from Customer c where c.Name = 'Andrea'") .UniqueResult<Customer>(); Order o = gm.Orders[0]; gm.Orders.Remove(o); am.Orders.Add(o); // Ora gm ha due ordini, am uno, sposto un ordine da un cliente ad un altro session.Flush(); } }