Пример #1
0
        public void CreateNew()
        {
            var customer = Session.QueryOver<Customer>().Take(1).List().Single();

            var order = new Order
                            {
                                Customer = customer,
                                DeliveryStatus = null,
                            };

            Session.Save(order);
            Session.Flush();
        }
Пример #2
0
        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();
            }
        }
 public void SpecifyOrder(Order order)
 {
     order.Specify(First<ValidationMessageHandler>.Then<SecurityMessageHandler>());
 }