如何解决代码优先实体框架的具有家庭关系的人员表
我首先使用实体框架代码来创建人员的家庭关系。
表为 People
和 Relationship
。
public class Person
{
public Person()
{
this.Relationships = new HashSet<Relationship>();
}
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Relationship> Relationships { get; set; }
}
public class Relationship
{
public Relationship()
{
this.People = new HashSet<Person>();
this.Relatives = new HashSet<Person>();
}
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Person> People { get; set; }
public virtual ICollection<Person> Relatives { get; set; }
}
要创建的表是
PersonRelationship (Person_Id,Relative_Id,Relationship_Id)
不知何故,它没有生成预期的 PersonRelationship
表。
谁能给点建议?
如果我尝试如下
public class Person
{
public Person()
{
this.Relationships = new HashSet<Relationship>();
}
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Relationship> Relationships { get; set; }
}
public class Relationship
{
public Relationship()
{
this.People = new HashSet<Person>();
}
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Person> People { get; set; }
}
RelationshipPersons
表将使用 RelationshipPersons (Person_Id,Relationship_Id)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。