在依赖类型“Bd.Domain.Entities.FootballGame”中找不到导航属性“FootballGame” [英] The navigation property 'FootballGame' was not found on the dependent type 'Bd.Domain.Entities.FootballGame'

查看:189
本文介绍了在依赖类型“Bd.Domain.Entities.FootballGame”中找不到导航属性“FootballGame”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  public class FootballGame 
{
[Key]
public Guid id_FootballGame {get;组; }

[ForeignKey(FootballGame)]
public Guid? FK_id_FootballGame {get;组; }
public virtual FootballGame PreviousFootballGame {get;组; }

[ForeignKey(FootballTeam)]
public Guid id_FootballTeam_owner {get;组; }
public virtual FootballTeam FootballTeamOwner {get;组; }

[ForeignKey(FootballTeam)]
public Guid id_FootballTeam_guest {get;组; }
public virtual FootballTeam FootballTeamGuest {get;组; }
}

public class FootballTeam
{
[Key]
public Guid id_FootballTeam {get;组; }
public string teamName {get;组;
}

我有以下类:

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

public DbSet< FootballTeam>足球队{get;组; }
public DbSet< FootballGame>足球游戏{get;组;
}

不幸的是,有一个例外:



'Bd.Domain.FootballGame'上的属性FK_id_FootballGame的ForeignKeyAttribute无效。在依赖类型
'Bd.Domain.FootballGame'上找不到导航
属性FootballGame。名称值应为有效的
导航属性名称。


我尝试删除这些行:

  [ForeignKey(FootballGame)] 
public virtual FootballGame PreviousFootballGame {get;组;

但是,出现另一个例外:



< blockquote>


'Bd.FootballGame'上的属性'id_FootballTeam_owner'的ForeignKeyAttribute无效。在依赖类型Bd.FootballGame上找不到导航属性FootballTeam
。名称值
应该是一个有效的导航属性名称。


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

解决方案

尝试这样:



< p $ p> public class FootballGame
{
[Key]
public Guid id_FootballGame {get;组; }

public Guid? FK_id_FootballGame {get;组; }
[ForeignKey(FK_id_FootballGame)]
public virtual FootballGame PreviousFootballGame {get;组; }

public Guid id_FootballTeam_owner {get;组; }
[ForeignKey(id_FootballTeam_owner)]
public virtual FootballTeam FootballTeamOwner {get;组; }

public Guid id_FootballTeam_guest {get;组; }
[ForeignKey(id_FootballTeam_guest)]
public virtual FootballTeam FootballTeamGuest {get;组; }
}


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.

解决方案

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

这篇关于在依赖类型“Bd.Domain.Entities.FootballGame”中找不到导航属性“FootballGame”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆