private void btnNewGame_Click(object sender, RoutedEventArgs e) { Game g = new Game(mapIDs[cmbMap.SelectedIndex]); Game_has_Player ghp1; Game_has_Player ghp2; using (db = new G2776_2Entities1()) { db.Game.Add(g); db.SaveChanges(); var game = from gam in db.Game orderby gam.GameID descending select gam; foreach (var a in game) // purkkaa, foreachin sijaan pitäis vaan ensimmäistä alkiota käyttää... { ghp1 = new Game_has_Player(a.GameID, pID[cmbPlayer.SelectedIndex]); ghp2 = new Game_has_Player(a.GameID, pID[cmbOpponent.SelectedIndex]); db.Game_has_Player.Add(ghp1); db.Game_has_Player.Add(ghp2); break; } db.SaveChanges(); } // start game with given map and players }