Beispiel #1
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter15.invoice");
         context.ExecuteStoreCommand("delete from chapter15.client");
     }
 }
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter8.donation");
         context.ExecuteStoreCommand("delete from chapter8.donor");
     }
 }
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter7.servicecall");
         context.ExecuteStoreCommand("delete from chapter7.technician");
     }
 }
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter10.message");
         context.ExecuteStoreCommand("delete from chapter10.member");
     }
 }
Beispiel #5
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter5.employee");
         context.ExecuteStoreCommand("delete from chapter5.department");
         context.ExecuteStoreCommand("delete from chapter5.company");
     }
 }
Beispiel #6
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter11.reservation");
         context.ExecuteStoreCommand("delete from chapter11.visitor");
         context.ExecuteStoreCommand("delete from chapter11.hotel");
     }
 }
Beispiel #7
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter14.account");
     }
 }
Beispiel #8
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter2.picturecategory");
     }
 }
Beispiel #9
0
        static void RunExample()
        {
            using (var context = new EFRecipesEntities())
            {
                context.Accounts.AddObject(new Account {
                    AccountNumber = "8675309", Balance = 100M, Name = "Robin Rosen"
                });
                context.Accounts.AddObject(new Account {
                    AccountNumber = "8535937", Balance = 25M, Name = "Steven Bishop"
                });
                context.SaveChanges();
            }

            using (var context = new EFRecipesEntities())
            {
                // get the account
                var account = context.Accounts.First(a => a.AccountNumber == "8675309");
                Console.WriteLine("Account for {0}", account.Name);
                Console.WriteLine("\tPrevious Balance: {0}", account.Balance.ToString("C"));

                // some other process updates the balance
                Console.WriteLine("[Rogue process updates balance!]");
                context.ExecuteStoreCommand("update chapter14.account set balance = 1000 where accountnumber = '8675309'");

                // update the account balance
                account.Balance = 10M;

                try
                {
                    Console.WriteLine("\tNew Balance: {0}", account.Balance.ToString("C"));
                    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())
            {
                // cleanup from previous tests
                context.ExecuteStoreCommand("delete from chapter4.productdetail");
                context.ExecuteStoreCommand("delete from chapter4.orderdetail");
                context.ExecuteStoreCommand("delete from chapter4.product");
                context.ExecuteStoreCommand("delete from chapter4.category");
                context.ExecuteStoreCommand("delete from chapter4.supplier");

                // add in our test data
                var s1 = new Supplier {
                    CompanyName = "Backcountry Supply", Country = "USA"
                };
                var s2 = new Supplier {
                    CompanyName = "Alpine Tent", Country = "Italy"
                };
                var s3 = new Supplier {
                    CompanyName = "Ace Footware", Country = "USA"
                };
                var c1 = new Category {
                    CategoryName = "Tents"
                };
                var c2 = new Category {
                    CategoryName = "Shoes/Boots"
                };
                var pd1 = new ProductDetail {
                    UnitPrice = 99.95M
                };
                var pd2 = new ProductDetail {
                    UnitPrice = 129.95M
                };
                var pd3 = new ProductDetail {
                    UnitPrice = 39.95M
                };
                var p1 = new Product {
                    ProductName = "Pup Tent", ProductDescription = "Small and packable tent", Discontinued = true, UnitsInStock = 4
                };
                var p2 = new Product {
                    ProductName = "Trail Boot", ProductDescription = "Perfect boot for hiking", Discontinued = false, UnitsInStock = 19
                };
                var p3 = new Product {
                    ProductName = "Family Tent", ProductDescription = "Sleeps 2 adults + 2 children", Discontinued = false, UnitsInStock = 10
                };
                var od1 = new OrderDetail {
                    UnitPrice = 39.95M, Quantity = 1
                };
                var od2 = new OrderDetail {
                    UnitPrice = 129.95M, Quantity = 2
                };
                var od3 = new OrderDetail {
                    UnitPrice = 99.95M, Quantity = 1
                };
                p1.Supplier      = s2;
                p1.Category      = c1;
                p1.ProductDetail = pd3;
                p1.OrderDetails.Add(od1);
                p2.Supplier = s3;
                p2.Category = c2;
                p2.OrderDetails.Add(od2);
                p2.ProductDetail = pd2;
                p3.Supplier      = s1;
                p3.Category      = c1;
                p3.ProductDetail = pd1;
                p3.OrderDetails.Add(od3);
                context.Products.AddObject(p1);
                context.Products.AddObject(p2);
                context.Products.AddObject(p3);
                context.SaveChanges();
            }
        }