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(); }
/// <summary> /// Create a new BMW object. /// </summary> /// <param name="carId">Initial value of the CarId property.</param> /// <param name="model">Initial value of the Model property.</param> /// <param name="year">Initial value of the Year property.</param> /// <param name="color">Initial value of the Color property.</param> /// <param name="collisionAvoidance">Initial value of the CollisionAvoidance property.</param> public static BMW CreateBMW(global::System.Int32 carId, global::System.String model, global::System.String year, global::System.String color, global::System.Boolean collisionAvoidance) { BMW bMW = new BMW(); bMW.CarId = carId; bMW.Model = model; bMW.Year = year; bMW.Color = color; bMW.CollisionAvoidance = collisionAvoidance; return(bMW); }