Hello everybody,

I'm trying to get started using NHibernate by doing the Summer of
NHibernate tutorials.

I have a test:

        [Test]
        public void CanDeleteCustomer()
        {
            Customer customer = GetDeletableCustomer();
            _provider.DeleteCustomer(customer);

            Customer testCustomer = GetDeletableCustomer();

            Assert.IsNull(testCustomer);
        }

This test invokes GetDeletableCustomer()

        private Customer GetDeletableCustomer()
        {
            return _provider.GetCustomerById(80);
        }

GetCustomerById() opens a session:

        public Customer GetCustomerById(int customerId)
        {
            using (ISession session = GetSession())
            {
                return session.Get<Customer>(customerId);
            }
        }

Later on my test invokes the method DeleteCustomer() which also opens
a session:

and DeleteCustomer()

        public void DeleteCustomer(Customer customer)
        {
            using (ISession session = GetSession())
            {
                using (ITransaction tx = session.BeginTransaction())
                {
                    try
                    {
                        session.Delete(customer);
                        session.Flush();
                        tx.Commit();
                    }
                    catch (NHibernate.HibernateException)
                    {
                        tx.Rollback();
                        throw;
                    }
                }
            }
        }


Now my question is, are these both sessions the problem?
If so, what would be an elegant way of solving this?

Many thanks in advance,

Jan Apel

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to