Exemplo n.º 1
0
 public void Update(Flug flight)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.Fluege.Update(flight);
         ctx.SaveChanges();
     }
 }
Exemplo n.º 2
0
        static FlugManager()
        {
            using (FlugDbContext ctx = new FlugDbContext())
            {
                ctx.Database.EnsureDeleted();
                ctx.Database.EnsureCreated();

                if (!ctx.Fluege.Any())
                {
                    var f1 = new Flug {
                        Abflugort = "Graz", Zielort = "Hamburg", Datum = DateTime.Now
                    };
                    var f2 = new Flug {
                        Abflugort = "Wien", Zielort = "London", Datum = DateTime.Now.AddHours(1)
                    };
                    var f3 = new Flug {
                        Abflugort = "Graz", Zielort = "Hamburg", Datum = DateTime.Now.AddHours(2)
                    };
                    var f4 = new Flug {
                        Abflugort = "Hamburg", Zielort = "Graz", Datum = DateTime.Now.AddHours(3)
                    };
                    var f5 = new Flug {
                        Abflugort = "Hamburg", Zielort = "Wien", Datum = DateTime.Now.AddHours(4)
                    };
                    var f6 = new Flug {
                        Abflugort = "Graz", Zielort = "Hamburg", Datum = DateTime.Now.AddHours(5)
                    };
                    var f7 = new Flug {
                        Abflugort = "Wien", Zielort = "London", Datum = DateTime.Now.AddHours(6)
                    };

                    var b1 = new Buchung {
                        PassagierId = 4711, Preis = 300
                    };
                    f1.Buchungen.Add(b1);

                    ctx.Fluege.AddRange(f1, f2, f3, f4, f5, f6, f7);
                    ctx.SaveChanges();
                }
            }

            using (FlugDbContext ctx = new FlugDbContext())
            {
                var all = ctx.Fluege.ToList();
                Debug.WriteLine(all.Count);
            }
        }