我创建了两个表。
表 1:具有 ParentId 和 ParentName 字段的父表。在此 ParentId 是主键。
表 2:具有 ChildId 和 ChildName 字段的子表。在此 ChildId 是主键。
我想将 ParentId 和 ChildId 放入另一个表中。所以我创建了名为 MappingParentChild 的表,其中 ParentId1,ChildId1。我希望这个 ParentId1 和 ChildId1 作为外键。我怎样才能做到这一点。
public class Parent
{
public int ParentId { get; set; } //Primary key
public string ParentName { get; set; }
}
public class Child
{
public int ChildId { get; set; } //Primary key
public string ChildName { get; set; }
}
public class MappingParentChild
{
public int Id { get; set; }
public int ParentId1 { get; set; } // want Foreign key for Parent(ParentId)
public int ChildId1 { get; set; }// want Foreign key for Child(ChildId)
}
public class MappingParentChildConfiguration :EntityTypeConfiguration<MappingParentChild>
{
public MappingParentChildConfiguration()
{
ToTable("MappingParentChild");
Property(m => m.Id).IsRequired();
Property(m => m.ParentId1).IsRequired();
Property(m => m.ChildId1).IsRequired();
}
}
我该怎么做。请帮帮我。