[Table("league_seasons")]
public class LeagueSeason
{
[Key]
[Column("league_season_id")]
public required int Id { get; set; }
[ForeignKey("League")]
[Column("league_id")]
public required int LeagueId { get; set; }
[ForeignKey("Season")]
[Column("season_id")]
public required int SeasonId { get; set; }
[Column("yahoo_league_season_id")]
public string? YahooLeagueSeasonId { get; set; }
[Column("num_teams")]
public required int NumTeams { get; set; }
[Column("num_playoff_teams")]
public int? NumPlayoffTeams { get; set; }
[Column("num_weeks")]
public required int NumWeeks { get; set; }
[Column("rivalry_weeks")]
public string? RivalryWeeks { get; set; }
[Column("nut_cup_week")]
public required int NutCupWeek { get; set; }
[Column("avg_points")]
public required double AvgPoints { get; set; }
[Column("avg_moves")]
public required double AvgMoves { get; set; }
[Column("completed")]
public required int Completed { get; set; }
[Column("create_date")]
public required DateTime CreateDate { get; set; }
[Column("modify_date")]
public required DateTime ModifyDate { get; set; }
// Relationships
public virtual required League League { get; set; }
public virtual required Season Season { get; set; }
public virtual required ICollection Teams { get; set; }
}
[Table("seasons")]
public class Season
{
[Key]
[Column("season_id")]
public required int Id { get; set; }
[Column("yahoo_season_id")]
public int? YahooSeasonId { get; set; }
[Column("name")]
public required string Name { get; set; }
[Column("start_date")]
public required DateOnly StartDate { get; set; }
[Column("end_date")]
public required DateOnly EndDate { get; set; }
[Column("create_date")]
public required DateTime CreateDate { get; set; }
[Column("modify_date")]
public required DateTime ModifyDate { get; set; }
// Relationships
public virtual ICollection LeagueSeasons { get; set; }
< /code>
Для следующих таблиц в моей базе данных: < /p>
CREATE TABLE `league_seasons` (
`league_season_id` INT(10) NOT NULL AUTO_INCREMENT,
`league_id` INT(10) NOT NULL,
`season_id` INT(10) NOT NULL,
`yahoo_league_season_id` VARCHAR(50) NULL DEFAULT NULL COMMENT 'Classified as their league id' COLLATE 'utf8mb3_general_ci',
`num_teams` INT(10) NOT NULL,
`num_playoff_teams` INT(10) NULL DEFAULT NULL,
`num_weeks` INT(10) NOT NULL,
`rivalry_weeks` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
`nut_cup_week` INT(10) NULL DEFAULT NULL,
`avg_points` DECIMAL(20,6) NULL DEFAULT NULL,
`avg_moves` DECIMAL(20,6) NULL DEFAULT NULL,
`completed` TINYINT(3) NOT NULL DEFAULT '0',
`create_date` DATETIME NULL DEFAULT 'CURRENT_TIMESTAMP',
`modify_date` DATETIME NULL DEFAULT 'CURRENT_TIMESTAMP',
PRIMARY KEY (`league_season_id`) USING BTREE,
UNIQUE INDEX `league_id_season_id` (`league_id`, `season_id`) USING BTREE,
INDEX `league_id` (`league_id`) USING BTREE,
INDEX `season_id` (`season_id`) USING BTREE,
INDEX `yahoo_league_season_id` (`yahoo_league_season_id`) USING BTREE
)
COLLATE='utf8mb3_general_ci'
ENGINE=InnoDB;
CREATE TABLE `seasons` (
`season_id` INT(10) NOT NULL AUTO_INCREMENT,
`yahoo_season_id` INT(10) NULL DEFAULT NULL,
`name` YEAR NOT NULL,
`start_date` DATE NOT NULL,
`end_date` DATE NOT NULL,
`create_date` DATETIME NULL DEFAULT 'CURRENT_TIMESTAMP',
`modify_date` DATETIME NULL DEFAULT 'CURRENT_TIMESTAMP' ON UPDATE (CURRENT_TIMESTAMP),
PRIMARY KEY (`season_id`) USING BTREE,
UNIQUE INDEX `yahoo_season_id` (`yahoo_season_id`) USING BTREE
)
COLLATE='utf8mb3_general_ci'
ENGINE=InnoDB;
< /code>
С следующим кодом: < /p>
int current_league_season_id = context.LeagueSeasons
.Include(ls => ls.Season)
.Where(ls => ls.LeagueId == selectedLeague)
.OrderByDescending(ls => ls.Season.Name)
.Select(ls => ls.Id)
.First();
Dictionary power_rankings = Calculations.CalculateLeaguePowerRankings(selectedLeague, context.LeagueSeasons.Find(current_league_season_id).Season.Name);
< /code>
///
/// Method that calculates league power rankings for a given season and returns a dictionary of manager_ids and power ranking score
///
///
///
///
public static Dictionary CalculateLeaguePowerRankings(int selectedLeague, int? year = null)
< /code>
However, the last line of that code throws the following exception with the Season relationship in that method parameter:
System.InvalidCastException: 'Unable to cast object of type 'System.Int32' to type 'System.String'.'
When I add the following code:
int current_season_id = context.LeagueSeasons
.Include(ls => ls.Season)
.Where(ls => ls.Id == current_league_season_id)
.Select(ls => ls.SeasonId)
.First();
Season current_season = context.Seasons.Find(current_season_id);
< /code>
Both current_league_season_id
и current_season_id возвращают допустимые идентификаторы целых чисел с записями, которые можно найти в базе данных. Кроме того, current_season_id является secorid_id , связанный с моим тестом current_league_season_id .
Я попытался изменить запрос Current_Season для использования. Где (. ..). Firstordefault () вместо .find () , но результаты одинаковы.
У меня есть следующие модели: < /p> [code][Table("league_seasons")] public class LeagueSeason { [Key] [Column("league_season_id")] public required int Id { get; set; }
[ForeignKey("League")] [Column("league_id")] public required int LeagueId { get; set; }
[ForeignKey("Season")] [Column("season_id")] public required int SeasonId { get; set; }
[Column("yahoo_league_season_id")] public string? YahooLeagueSeasonId { get; set; }
[Column("num_teams")] public required int NumTeams { get; set; }
[Column("num_playoff_teams")] public int? NumPlayoffTeams { get; set; }
[Column("num_weeks")] public required int NumWeeks { get; set; }
[Column("rivalry_weeks")] public string? RivalryWeeks { get; set; }
[Column("nut_cup_week")] public required int NutCupWeek { get; set; }
[Column("avg_points")] public required double AvgPoints { get; set; }
[Column("avg_moves")] public required double AvgMoves { get; set; }
[Column("completed")] public required int Completed { get; set; }
[Column("create_date")] public required DateTime CreateDate { get; set; }
[Column("modify_date")] public required DateTime ModifyDate { get; set; }
// Relationships public virtual required League League { get; set; } public virtual required Season Season { get; set; } public virtual required ICollection Teams { get; set; } }
[Table("seasons")] public class Season { [Key] [Column("season_id")] public required int Id { get; set; }
[Column("yahoo_season_id")] public int? YahooSeasonId { get; set; }
[Column("name")] public required string Name { get; set; }
[Column("start_date")] public required DateOnly StartDate { get; set; }
[Column("end_date")] public required DateOnly EndDate { get; set; }
[Column("create_date")] public required DateTime CreateDate { get; set; }
[Column("modify_date")] public required DateTime ModifyDate { get; set; }
// Relationships public virtual ICollection LeagueSeasons { get; set; }
< /code> Для следующих таблиц в моей базе данных: < /p> CREATE TABLE `league_seasons` ( `league_season_id` INT(10) NOT NULL AUTO_INCREMENT, `league_id` INT(10) NOT NULL, `season_id` INT(10) NOT NULL, `yahoo_league_season_id` VARCHAR(50) NULL DEFAULT NULL COMMENT 'Classified as their league id' COLLATE 'utf8mb3_general_ci', `num_teams` INT(10) NOT NULL, `num_playoff_teams` INT(10) NULL DEFAULT NULL, `num_weeks` INT(10) NOT NULL, `rivalry_weeks` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci', `nut_cup_week` INT(10) NULL DEFAULT NULL, `avg_points` DECIMAL(20,6) NULL DEFAULT NULL, `avg_moves` DECIMAL(20,6) NULL DEFAULT NULL, `completed` TINYINT(3) NOT NULL DEFAULT '0', `create_date` DATETIME NULL DEFAULT 'CURRENT_TIMESTAMP', `modify_date` DATETIME NULL DEFAULT 'CURRENT_TIMESTAMP', PRIMARY KEY (`league_season_id`) USING BTREE, UNIQUE INDEX `league_id_season_id` (`league_id`, `season_id`) USING BTREE, INDEX `league_id` (`league_id`) USING BTREE, INDEX `season_id` (`season_id`) USING BTREE, INDEX `yahoo_league_season_id` (`yahoo_league_season_id`) USING BTREE ) COLLATE='utf8mb3_general_ci' ENGINE=InnoDB;
CREATE TABLE `seasons` ( `season_id` INT(10) NOT NULL AUTO_INCREMENT, `yahoo_season_id` INT(10) NULL DEFAULT NULL, `name` YEAR NOT NULL, `start_date` DATE NOT NULL, `end_date` DATE NOT NULL, `create_date` DATETIME NULL DEFAULT 'CURRENT_TIMESTAMP', `modify_date` DATETIME NULL DEFAULT 'CURRENT_TIMESTAMP' ON UPDATE (CURRENT_TIMESTAMP), PRIMARY KEY (`season_id`) USING BTREE, UNIQUE INDEX `yahoo_season_id` (`yahoo_season_id`) USING BTREE ) COLLATE='utf8mb3_general_ci' ENGINE=InnoDB; < /code> С следующим кодом: < /p> int current_league_season_id = context.LeagueSeasons .Include(ls => ls.Season) .Where(ls => ls.LeagueId == selectedLeague) .OrderByDescending(ls => ls.Season.Name) .Select(ls => ls.Id) .First();
Dictionary power_rankings = Calculations.CalculateLeaguePowerRankings(selectedLeague, context.LeagueSeasons.Find(current_league_season_id).Season.Name); < /code> /// /// Method that calculates league power rankings for a given season and returns a dictionary of manager_ids and power ranking score /// /// /// /// public static Dictionary CalculateLeaguePowerRankings(int selectedLeague, int? year = null) < /code> However, the last line of that code throws the following exception with the Season relationship in that method parameter:
System.InvalidCastException: 'Unable to cast object of type 'System.Int32' to type 'System.String'.'
When I add the following code: int current_season_id = context.LeagueSeasons .Include(ls => ls.Season) .Where(ls => ls.Id == current_league_season_id) .Select(ls => ls.SeasonId) .First();
Season current_season = context.Seasons.Find(current_season_id); < /code> Both current_league_season_id[/code] и current_season_id возвращают допустимые идентификаторы целых чисел с записями, которые можно найти в базе данных. Кроме того, current_season_id является secorid_id , связанный с моим тестом current_league_season_id . Я попытался изменить запрос Current_Season для использования. Где (. ..). Firstordefault () вместо .find () , но результаты одинаковы.
Я делаю карточную игру и пытаюсь использовать JSON для сохранения данных карт. Тем не менее, я продолжаю получать ту же самую и ту же «указанный актерский состав по какой -то причине не действительна». Мой класс карт выглядит следующим образом:...
Я делаю карточную игру и пытаюсь использовать JSON для сохранения данных карт. Тем не менее, я продолжаю получать ту же самую и ту же «указанный актерский состав по какой -то причине не действительна». Мой класс карт выглядит следующим образом:...