I have this Scenario:
public class Table1
{
[Key]
public string Table1Code { get; set; }
public virtual List<Table2> Table2 { get; set; }
}
public class Table2
{
[Key]
public string Table2Code { get; set; }
public virtual List<Table1> Table1 { get; set; }
}
Then I create a configuration class for specifying the many to many table:
public class Table1Configuration : EntityTypeConfiguration<Table1>
{
public Table1Configuration()
{
HasMany(g => g.Table2)
.WithMany(r => r.Table1)
.Map(c =>
{
c.ToTable("Table1_Table2");
c.MapLeftKey("Table1Code");
c.MapRightKey("Table2Code");
});
}
}
Now I have to create a Table3
like this
public class Table3
{
[Key]
public string Table3Code { get; set; }
public string Table1Code { get; set; }
public string Table2Code { get; set; }
}
How can I add the foreign key for columns Table1Code
and Table2Code
to the table Table1_Table2
?
I don't need to add the foreign key to Table1
and Table2
but to the table Table1_Table2
.