Listato8()
private void Listato8()
{
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();
for (Int32 CustId = 1; CustId < 10; ++CustId)
{
Customer customer = new Customer("Customer", CustId.ToString());
for (Int32 I = 0; I < 10; ++I)
customer.Orders.Add(new Order(DateTime.Now, I * 10.00f));
session.Save(customer);
}
session.Flush();
}
using (ISession session = NHSessionManager.GetSession())
{
IList<Customer> allcustomer = session.CreateQuery("from Customer c join fetch c.Orders where c.Surname < 3")
.SetResultTransformer(NHibernate.CriteriaUtil.DistinctRootEntity)
.List<Customer>();
// IList<Customer> allcustomer = session.CreateCriteria(typeof (Customer)).List<Customer>();
foreach (Customer cust in allcustomer)
{
Console.WriteLine(cust.Orders.Count);
}
}
}