Пример #1
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter13.payment");
         context.ExecuteStoreCommand("delete from chapter13.account");
     }
 }
Пример #2
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter2.productwebinfo");
         context.ExecuteStoreCommand("delete from chapter2.product");
     }
 }
Пример #3
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter15.authorbook");
         context.ExecuteStoreCommand("delete from chapter15.book");
         context.ExecuteStoreCommand("delete from chapter15.author");
     }
 }
Пример #4
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter14.Instructor");
         context.ExecuteStoreCommand("delete from chapter14.Student");
         context.ExecuteStoreCommand("delete from chapter14.Person");
     }
 }
Пример #5
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter12.step");
         context.ExecuteStoreCommand("delete from chapter12.ingredient");
         context.ExecuteStoreCommand("delete from chapter12.recipe");
     }
 }
Пример #6
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter10.magazine");
         context.ExecuteStoreCommand("delete from chapter10.dvd");
         context.ExecuteStoreCommand("delete from chapter10.media");
     }
 }
Пример #7
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter5.reservation");
         context.ExecuteStoreCommand("delete from chapter5.executivesuite");
         context.ExecuteStoreCommand("delete from chapter5.room");
         context.ExecuteStoreCommand("delete from chapter5.hotel");
     }
 }
Пример #8
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter8.item");
     }
 }
Пример #9
0
        static void RunExample()
        {
            using (var context = new EFRecipesEntities())
            {
                var student = new Student {
                    Name = "Joan Williams", EnrollmentDate = DateTime.Parse("1/12/2010")
                };
                var instructor = new Instructor {
                    Name = "Rodger Keller", HireDate = DateTime.Parse("7/14/1992")
                };
                context.People.AddObject(student);
                context.People.AddObject(instructor);
                context.SaveChanges();
            }

            using (var context = new EFRecipesEntities())
            {
                // find the student and update the enrollment date
                var student = context.People.OfType <Student>().First(s => s.Name == "Joan Williams");
                Console.WriteLine("Updating {0}'s enrollment date", student.Name);

                // out-of-band update occurs
                Console.WriteLine("[Apply rogue update]");
                context.ExecuteStoreCommand(@"update chapter14.person set name = 'Joan Smith'
                        where personId = 
                         (select personId from chapter14.person where name = 'Joan Williams')");

                // change the enrollment date
                student.EnrollmentDate = DateTime.Parse("5/2/2010");
                try
                {
                    context.SaveChanges();
                }
                catch (OptimisticConcurrencyException ex)
                {
                    Console.WriteLine("Exception: {0}", ex.Message);
                }
            }

            Console.WriteLine("Press <enter> to continue...");
            Console.ReadLine();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            using (var context = new EFRecipesEntities())
            {
                // delete the previous test data
                context.ExecuteStoreCommand("delete from chapter4.contact");

                // insert some new test data
                context.Contacts.AddObject(new Customer {
                    Name = "Joan Ryan", Email = "*****@*****.**"
                });
                context.Contacts.AddObject(new Customer {
                    Name = "Robert Kelly", Email = "*****@*****.**"
                });
                context.Contacts.AddObject(new Employee {
                    Name = "Karen Stanford", HireDate = DateTime.Parse("1/21/2010")
                });
                context.Contacts.AddObject(new Employee {
                    Name = "Phil Marlowe", HireDate = DateTime.Parse("2/12/2009")
                });
                context.SaveChanges();
            }
        }