예제 #1
0
        static void CreateData()
        {
            using (FlugDbContext ctx = new FlugDbContext())
            {
                // ctx.Database.EnsureDeleted();
                ctx.Database.EnsureCreated();

                var f1 = new Flight { From = "Graz", To = "Hamburg", Date = DateTime.Now };
                var b1 = new Booking { Price = 300 };
                f1.Bookings.Add(b1);

                ctx.Flights.Add(f1);
                ctx.SaveChanges();

                #region addFurtherData

                var f2 = new Flight { From = "Vienna", To = "London", Date = DateTime.Now.AddHours(1) };
                var f3 = new Flight { From = "Graz", To = "Hamburg", Date = DateTime.Now.AddHours(2) };
                var f4 = new Flight { From = "Hamburg", To = "Graz", Date = DateTime.Now.AddHours(3) };
                var f5 = new Flight { From = "Vienna", To = "London", Date = DateTime.Now.AddHours(4) };
                var f6 = new Flight { From = "Graz", To = "Hamburg", Date = DateTime.Now.AddHours(5) };
                var f7 = new Flight { From = "Vienna", To = "London", Date = DateTime.Now.AddHours(6) };

                ctx.Flights.AddRange(f2, f3, f4, f5, f6);
                ctx.Flights.Add(f7);

                ctx.SaveChanges();

                #endregion

            }
        }
예제 #2
0
        static void RawSQL()
        {
            using (FlugDbContext ctx = new FlugDbContext())
            {
                // Please find the TVF GetFlights in the attached Textfile
                var flight = ctx.Flights
                             .FromSql("select * from dbo.GetFlights(@p0, @p1)", "Vienna", "London")
                             .Where(f => f.Date > DateTime.Today)
                             .ToList();

                Console.WriteLine("Count: " + flight.Count);
            }
        }
예제 #3
0
        static void CreateData()
        {
            using (FlugDbContext ctx = new FlugDbContext())
            {
                // ctx.Database.EnsureDeleted();
                ctx.Database.EnsureCreated();

                var f1 = new Flight {
                    From = "Graz", To = "Hamburg", Date = DateTime.Now
                };
                var b1 = new Booking {
                    Price = 300
                };
                f1.Bookings.Add(b1);

                ctx.Flights.Add(f1);
                ctx.SaveChanges();

                #region addFurtherData

                var f2 = new Flight {
                    From = "Vienna", To = "London", Date = DateTime.Now.AddHours(1)
                };
                var f3 = new Flight {
                    From = "Graz", To = "Hamburg", Date = DateTime.Now.AddHours(2)
                };
                var f4 = new Flight {
                    From = "Hamburg", To = "Graz", Date = DateTime.Now.AddHours(3)
                };
                var f5 = new Flight {
                    From = "Vienna", To = "London", Date = DateTime.Now.AddHours(4)
                };
                var f6 = new Flight {
                    From = "Graz", To = "Hamburg", Date = DateTime.Now.AddHours(5)
                };
                var f7 = new Flight {
                    From = "Vienna", To = "London", Date = DateTime.Now.AddHours(6)
                };

                ctx.Flights.AddRange(f2, f3, f4, f5, f6);
                ctx.Flights.Add(f7);

                ctx.SaveChanges();

                #endregion
            }
        }
예제 #4
0
        static void ShadowProperties()
        {
            using (FlugDbContext ctx = new FlugDbContext())
            {
                var flight    = ctx.Flights.First(f => f.Id == 1);
                var planeType = ctx.Entry(flight).Property("PlaneType").CurrentValue;

                Console.WriteLine("PlaneType: " + planeType);


                var flights = ctx.Flights
                              .Where(f => EF.Property <string>(f, "PlaneType") == "Airbus")
                              .ToList();

                Console.WriteLine("Count: " + flights.Count);
            }
        }
예제 #5
0
        static void RawSQL()
        {
            using (FlugDbContext ctx = new FlugDbContext())
            {
                // Please find the TVF GetFlights in the attached Textfile
                var flight = ctx.Flights
                                .FromSql("select * from dbo.GetFlights(@p0, @p1)", "Vienna", "London")
                                .Where(f => f.Date > DateTime.Today)
                                .ToList();

                Console.WriteLine("Count: " + flight.Count);
            }
        }
예제 #6
0
        static void ShadowProperties()
        {
            using (FlugDbContext ctx = new FlugDbContext())
            {
                var flight = ctx.Flights.First(f => f.Id == 1);
                var planeType = ctx.Entry(flight).Property("PlaneType").CurrentValue;

                Console.WriteLine("PlaneType: " + planeType);


                var flights = ctx.Flights
                                 .Where(f => EF.Property<string>(f, "PlaneType") == "Airbus")
                                 .ToList();

                Console.WriteLine("Count: " + flights.Count);
            }
        }