实体框架核心一对多:无法确定关系

时间:2018-02-02 02:06:20

标签: c# entity-framework .net-core relationship

我想在两个模型之间建立关系。在EF迁移添加时,我收到以下错误:

https://pastebin.com/xzBUN0qn

这是我的代码,我没有使用流利。

[Table("Teams")]
public class TeamModel
{
    [Key]
    public int Id { get; set; }
    public string Name { get; set; }
    public TeamType Type { get; set; }
    public TeamSubType SubType { get; set; }

    [NotMapped]
    public ICollection<CharacterModel> Members { get; set; }
}

[Table("Characters")]
public class CharacterModel
{
    [Key]
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public Gender Gender { get; set; }
    public int Money { get; set; }

    public TeamRanks? FactionRank { get; set; }
    public TeamRanks? GroupRank { get; set; }
    public int Health { get; set; }
    public double PosX { get; set; }
    public double PosY { get; set; }
    public double PosZ { get; set; }

    public TeamModel Faction { get; set; }
    public TeamModel Group { get; set; }
}

异常消息的第一行显示为:

System.InvalidOperationException: Unable to determine the relationship represented by navigation property 'CharacterModel.Faction' of type 'TeamModel'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

0 个答案:

没有答案