私は2つのテーブルを作成しました。
表 1: ParentId フィールドと ParentName フィールドを持つ親テーブル。この ParentId は主キーです。
表 2: ChildId フィールドと ChildName フィールドを持つ子テーブル。この ChildId は主キーです。
ParentId と ChildId を別のテーブルに取得したいので、ParentId1、ChildId1 を使用して MappingParentChild という名前のテーブルを作成しました。この 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();
}
}
これを行うにはどうすればよいですか。助けてください。