I have created two table.
Table 1: Parent table with ParentId and ParentName fields.In this ParentId is primary key.
Table 2: Child table with ChildId and ChildName fields.In this ChildId is primary key.
I want to get the ParentId and ChildId into another table.So icreated table in the name MappingParentChild with ParentId1,ChildId1.I want this ParentId1 and ChildId1 as foreign key.
How can i achive this.
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();
}
}
How can i do this.Please help me.
MappingParentChildclass? Because EF does not need it to create many-to-many relations - SOfanatic