コード例 #1
0
 private static void PrintAirlineCount()
 {
     using (var ctx = new AirTravelContext())
     {
         Console.WriteLine("Airline Count: {0}", ctx.Airlines.Count());
     }
 }
コード例 #2
0
 private static void RemoveData()
 {
     using (var ctx = new AirTravelContext())
     {
         ctx.Database.ExecuteSqlCommand("DELETE FROM Aircraft");
         ctx.Database.ExecuteSqlCommand("DELETE FROM Airlines");
     }
 }
コード例 #3
0
 private static void PrintAirlinesAndAircraft()
 {
     using (var ctx = new AirTravelContext())
     {
         foreach (var airline in ctx.Airlines.Include(a => a.Aircraft))
         {
             Console.WriteLine("{0}: {1}", airline.Code,
                               string.Join(", ", airline.Aircraft.Select(a => a.EquipmentCode)));
         }
     }
 }
コード例 #4
0
        private static void Seed()
        {
            using (var ctx = new AirTravelContext())
            {
                ctx.Airlines.Add(
                    new Airline
                {
                    Code     = "UA",
                    Name     = "United Airlines",
                    Aircraft = new List <Aircraft>
                    {
                        new Aircraft {
                            EquipmentCode = "788"
                        },
                        new Aircraft {
                            EquipmentCode = "763"
                        }
                    }
                });

                ctx.Airlines.Add(
                    new Airline
                {
                    Code     = "FR",
                    Name     = "Ryan Air",
                    Aircraft = new List <Aircraft>
                    {
                        new Aircraft {
                            EquipmentCode = "738"
                        },
                    }
                });

                ctx.SaveChanges();
            }
        }