There are the following classes
public class Act { public int Id {get;set;} public int OperationId {get;set;} public virtual Operation {get;set;} } public class Operation { public int Id {get;set;} public virtual ICollection<Program> Programs {get;set;} public virtual ICollection<Act> Acts {get;set;} } public class Program { public int Id {get;set;} public int? ActId {get;set;} public int OperationId {get;set;} public virtual Act Act {get;set;} public virtual Operation Operation {get;set;} } In development, I use the Code First approach, to create a many-to-many relationship between Program & Act to specified classes, I add navigation properties to Program : public virtual ICollection<Act> Acts {get;set;} , in Act : public virtual ICollection<Program> Programs {get;set;} . those. Classes began to look like this:
public class Program { public int Id {get;set;} public int? ActId {get;set;} public int OperationId {get;set;} public virtual Act Act {get;set;} public virtual Operation Operation {get;set;} public virtual ICollection<Act> Acts {get;set;} } public class Act { public int Id {get;set;} public int OperationId {get;set;} public virtual Operation {get;set;} public virtual ICollection<Program> Programs {get;set;} } I add a migration ( add-migration ) and this is what is generated:
public override void Up() { AddColumn("dbo.Acts", "Program_Id", c => c.Int()); AddColumn("dbo.Programs", "Act_Id", c => c.Int()); CreateIndex("dbo.Acts", "Program_Id"); CreateIndex("dbo.Programs", "Act_Id"); AddForeignKey("dbo.Acts", "Program_Id", "dbo.Programs", "Id"); AddForeignKey("dbo.Programs", "Act_Id", "dbo.Acts", "Id"); } Although I expect to create a link table of approximately the following form:
public class ProgramActs { public int ProgramId {get;set;} public int ActId {get;set;} } Please tell me why this is so. Is the necessary connection not created?
PS: Entity Framework 6.1.3
PSS: Yes, I know that the connection I need can be created using fluent api , but I would like to understand why it is not created using data annotations .