コード例 #1
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.Database.ExecuteSqlCommand("delete from chapter12.donation");
     }
 }
コード例 #2
0
        static void RunExample()
        {
            using (var context = new EFRecipesEntities())
            {
                context.Donations.Add(new Donation
                {
                    DonorName = "Robert Byrd",
                    Amount    = 350M
                });
                context.Donations.Add(new Donation
                {
                    DonorName = "Nancy McVoid",
                    Amount    = 250M
                });
                context.Donations.Add(new Donation
                {
                    DonorName = "Kim Kerns",
                    Amount    = 750M
                });
                Console.WriteLine("About to SaveChanges()");
                context.SaveChanges();
            }

            using (var context = new EFRecipesEntities())
            {
                var list = context.Donations.Where(o => o.Amount > 300M);
                Console.WriteLine("Donations over $300");
                foreach (var donor in list)
                {
                    Console.WriteLine("{0} gave {1}", donor.DonorName,
                                      donor.Amount.ToString("C"));
                }
            }
            Console.WriteLine("Press any key to close...");
            Console.ReadLine();
        }