示例#1
0
 public virtual void AddShopOrder(ShopOrder shopOrder, Customer customer)
 {
     shopOrder.Shop = this;
     shopOrder.Customer = customer;
     customer.ShopOrders.Add(shopOrder);
     this.ShopOrders.Add(shopOrder);
 }
        private void AddDummyData(ISession session)
        {
            var shopName = "Negozio di Pallino";
            using (ITransaction trans = session.BeginTransaction())
            {
                var shop = new Shop { Name = shopName };

                var customer = new Customer
                {
                    Name = "Mario",
                    Surname = "Rossi",
                    Address = "via Roma, 2"
                };
                try
                {
                    session.Save(customer);
                    session.Save(shop);
                    trans.Commit();
                }
                catch (Exception)
                {
                    trans.Rollback();
                    throw;
                }
            }
            using (ITransaction trans = session.BeginTransaction())
            {
                var shop = session.Get<Shop>(1);

                var customer = session.Get<Customer>(1);

                var order = new ShopOrder();
                order.AddItem("Fiesta", 2.30M, 1);
                order.AddItem("Delice", 2.30M, 1);

                shop.AddShopOrder(order, customer);

                try
                {
                    session.Save(shop);
                    trans.Commit();
                }
                catch (Exception)
                {
                    trans.Rollback();
                    throw;
                }
            }
        }