gpt4 book ai didi

c# - 在依赖类型 'FootballGame' 上找不到导航属性 'Bd.Domain.Entities.FootballGame'

转载 作者:太空狗 更新时间:2023-10-29 20:13:54 25 4
gpt4 key购买 nike

我正在创建我的第一个 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; }
}

我有以下类(class):

public class EFDbContext : DbContext
{
public EFDbContext() : base("name=EFDbContext") { }

public DbSet<FootballTeam> FootballTeams { get; set; }
public DbSet<FootballGame> FootballGames { get; set; }
}

不幸的是,有一个异常(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.

我试图删除这些行:

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

然而,另一个异常(exception)出现了:

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.

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

最佳答案

试试这个:

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

关于c# - 在依赖类型 'FootballGame' 上找不到导航属性 'Bd.Domain.Entities.FootballGame',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15032656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com