我有两张桌子,Accounts
张和Reservations
张.它们之间是一对多关系(一个帐户可以有多个预订),因此预约表有AccountId
列.
public class Account
{
public Guid Id { get; set; }
...
[JsonIgnore]
public List<Reservation> Reservations { get; set; } = new List<Reservation>();
}
public class Reservation
{
...
public Guid AccountId { get; set; }
[JsonIgnore]
public Account Account { get; set; }
}
实体框架本身就解决了这一问题,我在OnModelCreating()
中没有任何关于这个关系的具体内容.
现在我需要添加另一个类似的关系,当"父"帐户代表"常规"帐户创建预订时.因此,预订需要一个同时指向客户的ParentAccountId
列.原始关系需要保持不变.
我在预订类中添加了以下内容:
public Guid? ParentAccountId { get; set; }
[JsonIgnore]
public Account? ParentAccount { get; set; }
现在EF不再能够单独重新锁定关系,当我try 重建数据库时,我收到以下错误:
System.InvalidOperationException:无法确定由类型为"List"的导航"Account.Reservations"表示的关系.手动配置关系,或使用"[NotMapped]"属性或通过使用"OnModelCreating"中的"NotityTypeBuilder.Ignore"忽略此属性.
我如何才能正确配置它?