I have two tables, Project and BOM. Their relationship is many-to-many.
When I check my Migration class, I can see the below code that was automatically generated.
CreateTable(
"dbo.ProjectBOMs",
c => new
{
Project_Id = c.Int(nullable: false),
BOM_Id = c.Int(nullable: false),
})
.PrimaryKey(t => new { t.Project_Id, t.BOM_Id })
.ForeignKey("dbo.Projects", t => t.Project_Id, cascadeDelete: true)
.ForeignKey("dbo.BOMs", t => t.BOM_Id, cascadeDelete: true)
.Index(t => t.Project_Id)
.Index(t => t.BOM_Id);
However, when I try to access this table using the following method, it's not showing up.
using(var db = new ApplicationDbContext())
{
db.ProjectBOMs //<== there's no ProjectBOMs in db
}
Since ProjectBOMs table has already been automatically generated, do I have to write the following code again to be able to access the table?
modelBuilder.Entity<Project>()
.HasMany<BOM>(x => x.BOMs)
.WithMany(x => x.Projects)
.Map(x =>
{
x.MapLeftKey("Project_Id");
x.MapRightKey("BOM_Id");
x.ToTable("ProjectBOMs");
});