public void CreateNew() { var customer = new Customer { FirstName = "Test", LastName = "User", Type = CustomerType.Private, }; Session.Save(customer); Session.Flush(); }
public void RecreateDataBase() { using (var session = SessionManager.SessionFactory.OpenSession()) { using (TextWriter stringWriter = new StreamWriter("../../../Gen/DataBase.sql")) { new SchemaExport(SessionManager.Configuration).Execute(true, true, false, session.Connection, stringWriter); } } using (var session = SessionManager.SessionFactory.OpenSession()) using (var trans = session.BeginTransaction()) { // create initial data var product = new Product { Name = "Laptop", Price = 5000, Metadata = new Dictionary<string, ProductMetadata> { {"en", new ProductMetadata { Name = "Fuji", Description = "Hi performance laptop", }} } }; session.Save(product); session.Flush(); var customer = new Customer { FirstName = "Joe", LastName = "Smith", Type = CustomerType.Private, Orders = new List<Order>(), }; session.Save(customer); session.Flush(); var order = new Order { Customer = customer, Products = new List<ProductInOrder> { new ProductInOrder { Product = product, Quantity = 2, } } }; session.Save(order); session.Flush(); trans.Commit(); } }