Exemplo n.º 1
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter10.rental");
         context.ExecuteStoreCommand("delete from chapter10.vehicle");
     }
 }
Exemplo n.º 2
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter6.workertask");
         context.ExecuteStoreCommand("delete from chapter6.worker");
         context.ExecuteStoreCommand("delete from chapter6.task");
     }
 }
Exemplo n.º 3
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter2.poem");
         context.ExecuteStoreCommand("delete from chapter2.poet");
         context.ExecuteStoreCommand("delete from chapter2.meter");
     }
 }
Exemplo n.º 4
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter11.invoice");
         context.ExecuteStoreCommand("delete from chapter11.[order]"); // because we re-used tables in this chapter!
         context.ExecuteStoreCommand("delete from chapter11.customer");
     }
 }
Exemplo n.º 5
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter5.sectionstudent");
         context.ExecuteStoreCommand("delete from chapter5.section");
         context.ExecuteStoreCommand("delete from chapter5.student");
         context.ExecuteStoreCommand("delete from chapter5.course");
         context.ExecuteStoreCommand("delete from chapter5.instructor");
     }
 }
Exemplo n.º 6
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter12.[user]");
     }
 }
Exemplo n.º 7
0
        public Order InsertOrder()
        {
            using (var context = new EFRecipesEntities())
            {
                // remove previous test data
                context.ExecuteStoreCommand("delete from chapter9.[order]");

                var order = new Order {
                    Product = "Camping Tent", Quantity = 3, Status = "Received"
                };
                context.Orders.AddObject(order);
                context.SaveChanges();
                return(order);
            }
        }
Exemplo n.º 8
0
        static void RunExample()
        {
            using (var context = new EFRecipesEntities())
            {
                context.Agents.AddObject(new Agent {
                    Name = "Phillip Marlowe", Phone = "202 555-1212"
                });
                context.Agents.AddObject(new Agent {
                    Name = "Janet Rooney", Phone = "913 876-5309"
                });
                context.SaveChanges();
            }

            using (var context = new EFRecipesEntities())
            {
                // change the phone numbers
                var agent1 = context.Agents.Where(a => a.Name == "Janet Rooney").Single();
                var agent2 = context.Agents.Where(a => a.Name == "Phillip Marlowe").Single();
                agent1.Phone = "817 353-4458";
                context.SaveChanges();

                // update the other agent's number out-of-band
                context.ExecuteStoreCommand(@"update Chapter14.agent set Phone = '817 294-6059' where name = 'Phillip Marlowe'");

                // now change it using the model
                agent2.Phone = "817 906-2212";
                try
                {
                    context.SaveChanges();
                }
                catch (OptimisticConcurrencyException ex)
                {
                    Console.WriteLine("Exception caught updating phone number: {0}", ex.Message);
                }
            }

            using (var context = new EFRecipesEntities())
            {
                Console.WriteLine("-- All Agents --");
                foreach (var agent in context.Agents)
                {
                    Console.WriteLine("Agent: {0}, Phone: {1}", agent.Name, agent.Phone);
                }
            }

            Console.WriteLine("Press <enter> to continue...");
            Console.ReadLine();
        }
Exemplo n.º 9
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         using (var context = new EFRecipesEntities())
         {
             context.ExecuteStoreCommand("delete from chapter4.Member");
             context.Members.AddObject(new Member {
                 Name = "Robert Dewey", Email = "*****@*****.**"
             });
             context.Members.AddObject(new Member {
                 Name = "Nancy Steward", Email = "*****@*****.**"
             });
             context.Members.AddObject(new Member {
                 Name = "Robin Rosen", Email = "*****@*****.**"
             });
             context.SaveChanges();
         }
     }
 }