Пример #1
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter3.media");
     }
 }
Пример #2
0
 static void Cleanup()
 {
     using (var context = new EFRecipesEntities())
     {
         context.ExecuteStoreCommand("delete from chapter6.toyota");
         context.ExecuteStoreCommand("delete from chapter6.bmw");
         context.ExecuteStoreCommand("delete from chapter6.cardealer");
         context.ExecuteStoreCommand("delete from chapter6.dealer");
     }
 }
Пример #3
0
        static void RunExample()
        {
            using (var context = new EFRecipesEntities())
            {
                var d1 = new Dealer {
                    Name = "All Cities Toyota"
                };
                var d2 = new Dealer {
                    Name = "Southtown Toyota"
                };
                var d3 = new Dealer {
                    Name = "Luxury Auto World"
                };
                var c1 = new Toyota {
                    Model = "Camry", Color = "Green", Year = "2010", Dealer = d1
                };
                var c2 = new BMW {
                    Model = "310i", Color = "Blue", CollisionAvoidance = true, Year = "2010", Dealer = d3
                };
                var c3 = new Toyota {
                    Model = "Tundra", Color = "Blue", Year = "2010", Dealer = d2
                };
                context.Dealers.AddObject(d1);
                context.Dealers.AddObject(d2);
                context.Dealers.AddObject(d3);
                context.SaveChanges();
            }

            using (var context = new EFRecipesEntities())
            {
                context.ContextOptions.LazyLoadingEnabled = true;
                Console.WriteLine("Dealers and Their Cars");
                Console.WriteLine("======================");
                foreach (var dealer in context.Dealers)
                {
                    Console.WriteLine("\nDealer: {0}", dealer.Name);
                    foreach (var car in dealer.Cars)
                    {
                        string make = string.Empty;
                        if (car is Toyota)
                        {
                            make = "Toyota";
                        }
                        else if (car is BMW)
                        {
                            make = "BMW";
                        }
                        Console.WriteLine("\t{0} {1} {2} {3}", car.Year, car.Color, make, car.Model);
                    }
                }
            }

            Console.WriteLine("Press <enter> to continue...");
            Console.ReadLine();
        }
Пример #4
0
        static void RunExample()
        {
            using (var context = new EFRecipesEntities())
            {
                context.Media.AddObject(new Article {
                    Title = "Woodworkers' Favorite Tools"
                });
                context.Media.AddObject(new Article {
                    Title = "Building a Cigar Chair"
                });
                context.Media.AddObject(new Video {
                    Title = "Upholstering the Cigar Chair"
                });
                context.Media.AddObject(new Video {
                    Title = "Applying Finish to the Cigar Chair"
                });
                context.Media.AddObject(new Picture {
                    Title = "Photos of My Cigar Chair"
                });
                context.Media.AddObject(new Video {
                    Title = "Tour of My Woodworking Shop"
                });
                context.SaveChanges();
            }

            using (var context = new EFRecipesEntities())
            {
                var allMedia = from m in context.Media
                               let mediatype = m is Article ? 1 :
                                               m is Video ? 2 : 3
                                               orderby mediatype
                                               select m;
                Console.WriteLine("All Media sorted by type...");
                foreach (var media in allMedia)
                {
                    Console.WriteLine("Title: {0} [{1}]", media.Title, media.GetType().Name);
                }
            }

            Console.WriteLine("Press <enter> to continue...");
            Console.ReadLine();
        }