C
C#10mo ago
Pagano

Entity Framework Core Issue - Many to Many relationship

I got this error now:
Unable to create a 'DbContext' of type ''. The exception 'The 'Player' property 'PlayerMatch.Player' could not be mapped because the database provider does not support this type. Consider converting the property value to a type supported by the database using a value converter. See https://aka.ms/efcore-docs-value-converters for more information. Alternately, exclude the property from the model using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
Unable to create a 'DbContext' of type ''. The exception 'The 'Player' property 'PlayerMatch.Player' could not be mapped because the database provider does not support this type. Consider converting the property value to a type supported by the database using a value converter. See https://aka.ms/efcore-docs-value-converters for more information. Alternately, exclude the property from the model using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
1 Reply
Pagano
PaganoOP10mo ago
Here are my classes:
[Table("Player")]
internal class Player : User
{
[Key]
[ForeignKey("Id")]
public User User { get; private set; } = null!;
[DefaultValue(1000)]
[Range(0, float.MaxValue)]
public float MMR { get; private set; }
[DefaultValue(32)]
[Range(0, int.MaxValue)]
public int K { get; private set; }
[DefaultValue(0)]
[Range(0, int.MaxValue)]
[Column("Played Games")]
public int PlayedGames { get; private set; }
[DefaultValue(null)]
[Range(0, float.MaxValue)]
[Column("Win Rate")]
[DisplayFormat(DataFormatString = "{0:P2}")]
public float? WinRate { get; private set; }
[Required]
public LeagueRoles Role { get; private set; }

[Required]
[Column("Team")]
public Team Team { get; private set; } = null!;

public ICollection<PlayerMatch> PlayerMatches { get; } = [];
}

[Table("Match")]
internal class Match
{
[Key]
[Column("Id")]
public int Id { get; private set; }
[DefaultValue(null)]
public LeagueSides Winner { get; private set; }
public DateTime Timestamp { get; private set; } = DateTime.Now;

public ICollection<PlayerMatch> PlayerMatch { get; } = [];
}

[PrimaryKey(nameof(Player), nameof(Match))]
[Table("PlayerMatch")]
internal class PlayerMatch
{
public Player Player { get; set; } = null!;
public Match Match { get; set; } = null!;

public LeagueRoles Role { get; set; }
public LeagueChampions Champion { get; set; }
public LeagueSides Side { get; set; }
}
[Table("Player")]
internal class Player : User
{
[Key]
[ForeignKey("Id")]
public User User { get; private set; } = null!;
[DefaultValue(1000)]
[Range(0, float.MaxValue)]
public float MMR { get; private set; }
[DefaultValue(32)]
[Range(0, int.MaxValue)]
public int K { get; private set; }
[DefaultValue(0)]
[Range(0, int.MaxValue)]
[Column("Played Games")]
public int PlayedGames { get; private set; }
[DefaultValue(null)]
[Range(0, float.MaxValue)]
[Column("Win Rate")]
[DisplayFormat(DataFormatString = "{0:P2}")]
public float? WinRate { get; private set; }
[Required]
public LeagueRoles Role { get; private set; }

[Required]
[Column("Team")]
public Team Team { get; private set; } = null!;

public ICollection<PlayerMatch> PlayerMatches { get; } = [];
}

[Table("Match")]
internal class Match
{
[Key]
[Column("Id")]
public int Id { get; private set; }
[DefaultValue(null)]
public LeagueSides Winner { get; private set; }
public DateTime Timestamp { get; private set; } = DateTime.Now;

public ICollection<PlayerMatch> PlayerMatch { get; } = [];
}

[PrimaryKey(nameof(Player), nameof(Match))]
[Table("PlayerMatch")]
internal class PlayerMatch
{
public Player Player { get; set; } = null!;
public Match Match { get; set; } = null!;

public LeagueRoles Role { get; set; }
public LeagueChampions Champion { get; set; }
public LeagueSides Side { get; set; }
}
Want results from more Discord servers?
Add your server