导航属性';足球游戏';在依赖类型';Bd.Domain.实体.FootballGame';

本文关键字:Bd 类型 Domain 实体 依赖 FootballGame 游戏 属性 导航 | 更新日期: 2023-09-27 18:00:42

我正在创建我的第一个asp.net mvc3应用程序。我使用的是代码优先的方法。我有以下型号:

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; }
}

我有以下课程:

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

不幸的是,有一个例外:

类型上属性"FK_id_FootballGame"的ForeignKeyAttribute'Bd。领域FootballGame"无效。导航在依赖类型上找不到属性"FootballGame"'Bd。领域足球比赛。Name值应该是有效的导航属性名称。

我试图删除这些行:

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

然而,另一个例外出现了:

类型的属性"id_FootballTeam_owner"的ForeignKeyAttribute'Bd。FootballGame"无效。导航属性"FootballTeam"在依赖类型"Bd"上找不到。足球比赛。Name值应该是有效的导航属性名称。

我期待任何帮助。问候,丹尼斯。

导航属性';足球游戏';在依赖类型';Bd.Domain.实体.FootballGame';

试试这个:

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; }
}