Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 一对多关系,配置实体框架中引用的字段_C#_Entity Framework - Fatal编程技术网

C# 一对多关系,配置实体框架中引用的字段

C# 一对多关系,配置实体框架中引用的字段,c#,entity-framework,C#,Entity Framework,以下是域: public class Person : Entity { public int Id { get; set; } pucli ICollection<PersonChild> Children } public class PersonChild { public int Id { get; set; } public int PersonId { get; set; } public Person Person { get;

以下是域:

public class Person : Entity
{
    public int Id { get; set; }
    pucli ICollection<PersonChild> Children
}

public class PersonChild
{
    public int Id { get; set; }
    public int PersonId { get; set; }
    public Person Person { get; set; }
    public int ChildId { get; set; }
    public Person Child { get; set; }
}

我的问题是如何配置Person的Children属性以引用PersonChild中的PersonId?我的当前配置继续引用ChildID。

我的问题的解决方案是指定在配置中引用哪个字段:

HasRequired(p => p.Person).WithMany().HasForeignKey(pc => pc.PersonId);
HasRequired(pc => pc.Person).WithMany(p => p.Children).HasForeignKey(pc => pc.PersonId);