public void Customer_Address_OneWayRelation() { object addressId; using (var session = SessionFactory.OpenSession()) using (var transaction = session.BeginTransaction()) { Customer customer = new Customer(){FirstName = "Name", LastName = "LastName"}; Address address = new Address() { City = "Cracow", Country = "Poland", PostalCode = "30-133", Street = "Lea", StreetNumber = "116" }; address.Customer = customer; addressId = session.Save(address); transaction.Commit(); } using (var session = SessionFactory.OpenSession()) { Address addressSecond = session.Get<Address>(addressId); addressSecond.Customer.Should().NotBeNull(); } }
private void UpdateCustomer(Customer customer) { var session = SessionFactory.GetCurrentSession(); using (var transaction = session.BeginTransaction()) { customer.FirstName = "John"; transaction.Commit(); } }
private void UpdateCustomer(Customer customer) { using (var session = SessionFactory.OpenSession()) using (var transaction = session.BeginTransaction()) { session.Update(customer); transaction.Commit(); } }
private void Create() { using (var session = OpenNamedSession("Create")) { var customer = new Customer() { FirstName = "John", LastName = "Cleese" }; _customerId = session.Save(customer); session.Flush(); } }
protected override void PopulateDatabase() { using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { Customer customer = new Customer { FirstName = "Terry", LastName = "Gilliam" }; customer.Orders.Add(new Order() { Value = 10, Customer = customer }); CustomerId = session.Save(customer); transaction.Commit(); } }
protected override void PopulateDatabase() { using(ISession session = SessionFactory.OpenSession()) using(ITransaction transaction = session.BeginTransaction()) { for(int i = 0; i < 10; i++) { Customer customer = new Customer { FirstName = "Terry" + i.ToString(), LastName = "Gilliam" + i.ToString() }; for (int j = 10 - i; j > 0; j--) { customer.Orders.Add(new Order() {Value = i, Customer = customer}); } session.Save(customer); } transaction.Commit(); } }
public Form(object customerId, ISessionFactory sessionFactory) { _sessionFactory = sessionFactory; _session = _sessionFactory.OpenSession(); _model = _session.Get<Customer>(customerId); }