public MainWindow() { InitializeComponent(); using (var ct = new TimeTable()) { var cityList = ct.City.Select(q => new { q.Id, q.Name }).ToList(); foreach (var item in cityList) { StartBox.Items.Add(item.Name); sn.Add(new ShortName(item.Name, (int)item.Id)); } } }
private void DestinationBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { var item = sender as ComboBox; var selection = item.SelectedItem as string; if (item.SelectedItem != null) { ShortName selectedCity = sn.Single(s => s.Name == selection); using (var ct = new TimeTable()) { var cityList = ct.Departure .Include(b => b.Connection) .Where(q => q.Connection.StartId == DestId && q.Connection.DestinationId == selectedCity.Id) .Include(c => c.Connection.Destination) .Include(c => c.Connection.Start) .Include(c => c.Connection.Train) .Select(q => new { FROM = q.Connection.Start.Name, TO = q.Connection.Destination.Name, DEPARTURE = q.Time, TRAVEL_TIME = q.TravelTime, TRAIN = q.Connection.Train.Name }).ToList(); grid.ItemsSource = cityList; } } }