public void Update(Customer customer) { using (ISession session = NHibernateHelper.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Update(customer); transaction.Commit(); } } }
public void Can_add_new_customer() { var customer = new Customer { Firstname= "Apple", Lastname = "Dethero", DateCreated = DateTime.Now}; ICustomerRepository repository = new CustomerRepository(); repository.Add(customer); // use session to try to load the customer using (ISession session = _sessionFactory.OpenSession()) { var fromDb = session.Get<Customer>(customer.CustomerID); // Test that the customer was successfully inserted Assert.IsNotNull(fromDb); Assert.AreNotSame(customer, fromDb); Assert.AreEqual(customer.Firstname, fromDb.Firstname); } }
private bool IsInCollection(Customer customer, ICollection<Customer> fromDb) { foreach (var item in fromDb) if (customer.CustomerID == item.CustomerID) return true; return false; }