我想在两个模型之间建立关系。在EF迁移添加时,我收到以下错误:
这是我的代码,我没有使用流利。
[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'.