我有这个型号和配置
public class Person
{
public int? FatherId { get; set; }
public virtual Person Father { get; set; }
public int? MotherId { get; set; }
public virtual Person Mother { get; set; }
public virtual List<Person> Childs { get; set; }
}
class PersonConfiguration : EntityTypeConfiguration<Person>
{
public PersonConfiguration()
{
HasOptional(e => e.Father).WithMany(e => e.Childs)
.HasForeignKey(e => e.FatherId);
HasOptional(e => e.Mother).WithMany(e => e.Childs)
.HasForeignKey(e => e.MotherId);
}
}
我在类型为初始值的情况下收到此错误。
指定的架构无效。错误:(151,6):错误 0040:类型
Person_Father 未在命名空间 ExamModel (Alias=Self) 中定义。
有没有办法映射Childs
两个属性(motherId 和fatherId)的属性?
不可能将两个导航属性映射到单个集合属性。它看起来很可笑,但你必须有两个集合属性
public class Person
{
public int? FatherId { get; set; }
public virtual Person Father { get; set; }
public int? MotherId { get; set; }
public virtual Person Mother { get; set; }
public virtual List<Person> ChildrenAsFather { get; set; }
public virtual List<Person> ChildrenAsMother { get; set; }
}
class PersonConfiguration : EntityTypeConfiguration<Person>
{
public PersonConfiguration()
{
HasOptional(e => e.Father).WithMany(e => e.ChildrenAsFather)
.HasForeignKey(e => e.FatherId);
HasOptional(e => e.Mother).WithMany(e => e.ChildrenAsMother)
.HasForeignKey(e => e.MotherId);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)