The navigation property "FootballGame" was not found on the dependent type "Bd.Domain.Entities.FootballGame"

I am creating my first asp.net mvc3 application. I use the first code methodology. I have the following models:

public class FootballGame { [Key] public Guid id_FootballGame { get; set; } [ForeignKey("FootballGame")] public Guid? FK_id_FootballGame { get; set; } public virtual FootballGame PreviousFootballGame { get; set; } [ForeignKey("FootballTeam")] public Guid id_FootballTeam_owner { get; set; } public virtual FootballTeam FootballTeamOwner { get; set; } [ForeignKey("FootballTeam")] public Guid id_FootballTeam_guest { get; set; } public virtual FootballTeam FootballTeamGuest { get; set; } } public class FootballTeam { [Key] public Guid id_FootballTeam { get; set; } public string teamName { get; set; } } 

And I have the following class:

 public class EFDbContext : DbContext { public EFDbContext() : base("name=EFDbContext") { } public DbSet<FootballTeam> FootballTeams { get; set; } public DbSet<FootballGame> FootballGames { get; set; } } 

Unfortunately, there is an exception:

ForeignKeyAttribute in the 'FK_id_FootballGame' property of type 'Bd.Domain.FootballGame' is not valid. The navigation property 'FootballGame' was not found on the dependent type 'Bd.Domain.FootballGame. The Name value must be a valid navigation property name.

I tried to remove these lines:

 [ForeignKey("FootballGame")] public virtual FootballGame PreviousFootballGame { get; set; } 

However, another exception appears:

ForeignKeyAttribute on the id_FootballTeam_owner property of type "Bd.FootballGame" is invalid. Navigation property 'FootballTeam' not found on dependent type 'Bd.FootballGame'. Name must be a valid name for the navigation property.

I look forward to any help. Regards, Denis.

+7
source share
1 answer

Try the following:

 public class FootballGame { [Key] public Guid id_FootballGame { get; set; } public Guid? FK_id_FootballGame { get; set; } [ForeignKey("FK_id_FootballGame")] public virtual FootballGame PreviousFootballGame { get; set; } public Guid id_FootballTeam_owner { get; set; } [ForeignKey("id_FootballTeam_owner")] public virtual FootballTeam FootballTeamOwner { get; set; } public Guid id_FootballTeam_guest { get; set; } [ForeignKey("id_FootballTeam_guest")] public virtual FootballTeam FootballTeamGuest { get; set; } } 
+8
source

All Articles