public Player(int sourceReference, string name, Club currentClub) : this() { SourceReference = sourceReference; Name = name; currentClub.AddCurrentPlayer(this); }
public static void AddFormerPlayersToClub(Club club, params Player[] players) { foreach (var player in players) { club.AddFormerPlayer(player); } }
private static void SaveSampleData(ISessionFactory sessionFactory) { using (var session = sessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { // create a couple of Clubs with some players var liverpool = new Club(1, "Liverpool"); var chelsea = new Club(2, "Chelsea"); var realMadrid = new Club(3, "Real Madrid"); var stevieG = new Player(1, "Steven Gerrard", liverpool); var fernandoTorres = new Player(2, "Fernando Torres", chelsea); var joeCole = new Player(3, "Joe Cole", liverpool); //I know this is not right, just testing the mappings! var xabiAlonso = new Player(4, "Xabi Alonso", realMadrid); var jamieCarragher = new Player(5, "Jamie Carragher", liverpool); var dirkKuyt = new Player(6, "Dirk Kuyt", liverpool); var fatFrank = new Player(7, "Frank Lampard", chelsea); AddFormerPlayersToClub(liverpool, fernandoTorres, xabiAlonso); AddFormerPlayersToClub(chelsea, joeCole); // save both stores, this saves everything else via cascading session.SaveOrUpdate(liverpool); session.SaveOrUpdate(chelsea); session.SaveOrUpdate(realMadrid); transaction.Commit(); } session.Clear(); } }
private static void WriteClubPretty(Club club) { Console.WriteLine(club.CompactName); Console.WriteLine(" Current players:"); foreach (var player in club.CurrentPlayers) { Console.WriteLine(" " + player.Name); } Console.WriteLine(" Former Players:"); foreach (var player in club.FormerPlayers) { Console.WriteLine(" " + player.Name); } Console.WriteLine(); }