1

我首先使用实体​​框架代码进行了以下设置:-

public Player
{
    [Key]
    public int PlayerId { get; set; }

    public int? ClubId { get; set; }
    public virtual Club Club { get; set; }
}

public class Club
{
    public int ClubId { get; set; }

    public string Name { get; set; }
}

我想将“Player”类中的属性“Club”重命名为“CurrentClub”,因为它在我的应用程序中更有意义,但是这会失败,因为它不遵循 EF 开箱即用的命名约定。

如何成功重命名该属性?

从我所见,我认为我可以使用 [ForeignKey("Name")] 属性,但是我找不到它的参考。我可以看到帖子说它已经移动了命名空间......但我仍然找不到它。我正在使用 .NET 4.0,但在我的机器上安装了 .NET 4.5。

ForeignKey 属性是正确的方法,还是我需要做一些模型绑定?如果是这样,我需要什么?

4

0 回答 0