public List <MlbGameDto> GetGames(int numberGameDays, bool loadPlayers) { lock (_lockObject) { List <MlbShortGame> mlbShortGameList = new List <MlbShortGame>(); List <MlbGameDto> mlbGameList = new List <MlbGameDto>(); using (NpgsqlConnection npgsqlConnection = new NpgsqlConnection(ConnectionString)) { npgsqlConnection.Open(); const string sqlCommandText = "select * from mlb.get_games(@number_games_days)"; using (NpgsqlCommand npgsqlCommand = new NpgsqlCommand(sqlCommandText, npgsqlConnection)) { npgsqlCommand.CommandType = CommandType.Text; NpgsqlParameter npgsqlParameter1 = new NpgsqlParameter("number_games_days", numberGameDays); npgsqlCommand.Parameters.Add(npgsqlParameter1); using (NpgsqlDataReader npgsqlDataReader = npgsqlCommand.ExecuteReader()) { if (!npgsqlDataReader.HasRows) { const string message = "GetGames() has no rows"; Logger.Info(message); return(mlbGameList); } while (npgsqlDataReader.Read()) { Guid gameId = npgsqlDataReader.GetGuid("game_id"); // DateTime startDateTime = npgsqlDataReader.GetDateTime("schedule"); DateTime startDateTime = npgsqlDataReader.GetDateTime("start_time"); Guid homeTeamId = npgsqlDataReader.GetGuid("home_id"); Guid awayTeamId = npgsqlDataReader.GetGuid("away_id"); Guid? homePitcherId = npgsqlDataReader.GetNullableGuid("home_pitcher_id"); Guid? awayPitcherId = npgsqlDataReader.GetNullableGuid("away_pitcher_id"); MlbShortGame mlbShortGame = new MlbShortGame { GameId = gameId, StartDateTime = startDateTime, HomeTeamId = homeTeamId, AwayTeamId = awayTeamId, HomePitcherId = homePitcherId, AwayPitcherId = awayPitcherId }; mlbShortGameList.Add(mlbShortGame); } } } } foreach (MlbShortGame mlbShortGame in mlbShortGameList) { MlbGameDto mlbGame = CreateGameDto(mlbShortGame, loadPlayers); mlbGameList.Add(mlbGame); } return(mlbGameList); } }