Пример #1
0
        static void RunExample()
        {
            using (var context = new EFRecipesEntities())
            {
                // static order status
                var assemble = new OrderStatus
                {
                    OrderStatusId = 1,
                    Status        = "Assemble"
                };
                var test = new OrderStatus
                {
                    OrderStatusId = 2,
                    Status        = "Test"
                };
                var ship = new OrderStatus
                {
                    OrderStatusId = 3,
                    Status        = "Ship"
                };
                context.OrderStatus.AddObject(assemble);
                context.OrderStatus.AddObject(test);
                context.OrderStatus.AddObject(ship);

                var order = new Order
                {
                    Description = "HAL 9000 Supercomputer",
                    OrderStatus = assemble
                };
                context.Orders.AddObject(order);
                context.SaveChanges();
                order.OrderStatus = ship;
                try
                {
                    context.SaveChanges();
                }
                catch (Exception)
                {
                    Console.WriteLine("Oops...better test first.");
                }
                order.OrderStatus = test;
                context.SaveChanges();
                order.OrderStatus = ship;
                context.SaveChanges();
            }

            using (var context = new EFRecipesEntities())
            {
                foreach (var order in context.Orders)
                {
                    Console.WriteLine("Order {0} [{1}], status = {2}",
                                      order.OrderId.ToString(),
                                      order.Description,
                                      order.OrderStatus.Status);
                }
            }
            Console.WriteLine("Press any key to close...");
            Console.ReadLine();
        }
Пример #2
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter12.[order]");
         context.ExecuteStoreCommand("delete from chapter12.orderstatus");
     }
 }