partial void DeleteFLIGHT(FLIGHT instance);
 partial void UpdateFLIGHT(FLIGHT instance);
 partial void InsertFLIGHT(FLIGHT instance);
 private void detach_FLIGHTs1(FLIGHT entity)
 {
     this.SendPropertyChanging();
     entity.AIRPORT1 = null;
 }
 private void attach_FLIGHTs1(FLIGHT entity)
 {
     this.SendPropertyChanging();
     entity.AIRPORT1 = this;
 }
        /// <summary>
        /// Generate Flight Paths and submit them to the database using VS SQL Connection
        /// </summary>
        public static void setPaths()
        {
            //Get Flights
            using (DatabaseClassDataContext database = new DatabaseClassDataContext())
            {
                //Initial Association of Paths with Flights
                List <FLIGHT> flightsFetched = database.FLIGHTs.ToList();
                List <PATH>   pathsCreated   = new List <PATH>();
                foreach (FLIGHT f in flightsFetched)
                {
                    PATH path = new PATH()
                    {
                        airportname_2 = f.arrival_airport,
                        aiportname_1  = f.departure_airport,
                        distance      = f.distance,
                        flight_id     = f.Flight_id,
                    };
                    pathsCreated.Add(path);
                }

                database.PATHs.InsertAllOnSubmit(pathsCreated);
                database.SubmitChanges();

                //Generate a few flights with more than one path.
                List <AIRPORT> canadianAirports = database.AIRPORTs.Where(x => x.MAJOR_CITY.COUNTRY.Name == "Canada").ToList();
                List <AIRPORT> usAirports       = database.AIRPORTs.Where(x => x.MAJOR_CITY.COUNTRY.Name == "US").ToList();
                List <AIRPORT> mexicoAirports   = database.AIRPORTs.Where(x => x.MAJOR_CITY.COUNTRY.Name == "Mexico").ToList();

                //Alternate frequency between countries for variation
                int freqCanUS  = 5;
                int freqCanMex = 2;
                int freqMexUS  = 3;

                //Factor for Minimum Range Distance of Flight
                int minimumDistFactor = 3;

                //US -Canada
                for (int i = 0; i < freqCanUS; i++)
                {
                    FLIGHT flight1 = generateFlight(database, canadianAirports[_random.Next(0, canadianAirports.Count)], usAirports[_random.Next(0, usAirports.Count)], _random.Next(2000, 5000));
                    database.FLIGHTs.InsertOnSubmit(flight1);
                    PATH p1 = new PATH()
                    {
                        airportname_2 = usAirports[_random.Next(0, usAirports.Count)].Name,
                        aiportname_1  = flight1.departure_airport,
                        distance      = flight1.distance - _random.Next(100, flight1.distance / minimumDistFactor),
                        flight_id     = flight1.Flight_id,
                    };

                    PATH p2 = new PATH()
                    {
                        airportname_2 = flight1.arrival_airport,
                        aiportname_1  = p1.airportname_2,
                        distance      = flight1.distance - p1.distance,
                        flight_id     = flight1.Flight_id,
                    };

                    database.PATHs.InsertOnSubmit(p1);
                    database.PATHs.InsertOnSubmit(p2);
                }

                //Mexico and Canada
                for (int i = 0; i < freqCanMex; i++)
                {
                    FLIGHT flight1 = generateFlight(database, canadianAirports[_random.Next(0, canadianAirports.Count)], mexicoAirports[_random.Next(0, mexicoAirports.Count)], _random.Next(4000, 6000));
                    database.FLIGHTs.InsertOnSubmit(flight1);
                    PATH p1 = new PATH()
                    {
                        airportname_2 = canadianAirports[_random.Next(0, canadianAirports.Count)].Name,
                        aiportname_1  = flight1.departure_airport,
                        distance      = flight1.distance - _random.Next(100, flight1.distance / minimumDistFactor),
                        flight_id     = flight1.Flight_id,
                    };

                    PATH p2 = new PATH()
                    {
                        airportname_2 = flight1.arrival_airport,
                        aiportname_1  = p1.airportname_2,
                        distance      = flight1.distance - p1.distance,
                        flight_id     = flight1.Flight_id,
                    };

                    database.PATHs.InsertOnSubmit(p1);
                    database.PATHs.InsertOnSubmit(p2);
                }


                //Mexico-US
                for (int i = 0; i < freqMexUS; i++)
                {
                    FLIGHT flight1 = generateFlight(database, usAirports[_random.Next(0, usAirports.Count)], usAirports[_random.Next(0, usAirports.Count)], _random.Next(3000, 4000));
                    database.FLIGHTs.InsertOnSubmit(flight1);
                    PATH p1 = new PATH()
                    {
                        airportname_2 = usAirports[_random.Next(0, usAirports.Count)].Name,
                        aiportname_1  = flight1.departure_airport,
                        distance      = flight1.distance - _random.Next(100, flight1.distance / minimumDistFactor),
                        flight_id     = flight1.Flight_id,
                    };

                    PATH p2 = new PATH()
                    {
                        airportname_2 = flight1.arrival_airport,
                        aiportname_1  = p1.airportname_2,
                        distance      = flight1.distance - p1.distance,
                        flight_id     = flight1.Flight_id,
                    };

                    database.PATHs.InsertOnSubmit(p1);
                    database.PATHs.InsertOnSubmit(p2);
                }
                database.SubmitChanges();
            }
        }