Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'm using code first 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:

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

I tried to remove these lines:

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

However, another exception to appear:

The ForeignKeyAttribute on property 'id_FootballTeam_owner' on type 'Bd.FootballGame' is not valid. The navigation property 'FootballTeam' was not found on the dependent type 'Bd.FootballGame'. The Name value should be a valid navigation property name.

I look forward to any help. Regards, Denis.

like image 949
Denis Avatar asked Feb 22 '13 20:02

Denis


1 Answers

Try this:

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; }
}
like image 200
MarcinJuraszek Avatar answered Oct 14 '22 20:10

MarcinJuraszek