I have a table which links to itself in a many to many self join. The tables are created correctly but Entity Framework is adding an additional Entity_ID field in the link table.
CREATE TABLE dbo.LinKTable
(
EntityAID int NOT NULL,
EntityBID int NOT NULL,
Entity_ID int NULL, <-- This should not be here.
Active bit NOT NULL
)
Where is this erroneous link / column coming from!?
POCO Declarations
Entity
public int ID { get; set; }
public virtual ICollection<LinkTable> links { get; set; }
LinkTable
public int EntityAID { get; set; }
public int EntityBID { get; set; }
public Entity EntityA { get; set; }
public Entity EntityB { get; set; }
public bool Active { get; set; }
DBContext
modelBuilder.Entity<Entity>().ToTable("Entity", "dbo").HasKey(am => new { am.EntityAID, am.EntityBID });
modelBuilder.Entity<Entity>().HasRequired(am => am.EntityA).WithMany().HasForeignKey(am => am.EntityAID).WillCascadeOnDelete(false);
modelBuilder.Entity<Entity>().HasRequired(am => am.EntityB).WithMany().HasForeignKey(am => am.EntityBID).WillCascadeOnDelete(false);
Edit:
This is what I am trying to model. An entity links to another entity with an additional attribute of active. It is a many to many relationship (An entity can link to many other entities) with an additional attribute.