コード例 #1
0
 static void Cleanup()
 {
     using (var context = new EFRecipeEntities())
     {
         context.ExecuteStoreCommand("delete from chapter8.competitor");
         context.ExecuteStoreCommand("delete from chapter8.event");
         context.ExecuteStoreCommand("delete from chapter8.venue");
     }
 }
コード例 #2
0
        static void RunExample()
        {
            using (var context = new EFRecipeEntities())
            {
                var venue = new Venue {
                    Name = "City Center Hall"
                };
                var event1 = new Event {
                    Name = "All Star Boxing"
                };
                event1.Competitors.Add(new Competitor {
                    Name = "Big Joe Green"
                });
                event1.Competitors.Add(new Competitor {
                    Name = "Terminator Tim"
                });
                venue.Events.Add(event1);
                context.Venues.AddObject(venue);
                context.SaveChanges();
            }

            using (var context = new EFRecipeEntities())
            {
                foreach (var venue in context.Venues)
                {
                    Console.WriteLine("Venue: {0}", venue.Name);
                    context.LoadProperty(venue, v => v.Events);
                    foreach (var evt in venue.Events)
                    {
                        Console.WriteLine("\tEvent: {0}", evt.Name);
                        Console.WriteLine("\t--- Competitors ---");
                        context.LoadProperty(evt, e => e.Competitors);
                        foreach (var competitor in evt.Competitors)
                        {
                            Console.WriteLine("\t{0}", competitor.Name);
                        }
                    }
                }
            }

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