I am running into the following error while trying to migrate a database in Entity Framework.
The specified association foreign key columns 'question_set_id' are invalid. The number of columns specified must match the number of primary key columns.
I dropped the original primary key QuestionSetId and created a composite key relationship. The columns in the composite key relationship also map to foreign keys. I'm not sure what the issue is.
Here is the associated entity.
public class QuestionSet
{
[Key, Column(Order = 1)]
public long TitleId { get; set; }
[ForeignKey("TitleId")]
public virtual Title Title { get; set; }
[Key, Column(Order = 0)]
public long ReviewCycleId { get; set; }
[ForeignKey("ReviewCycleId")]
public virtual ReviewCycle ReviewCycle { get; set; }
public virtual List<Question> Questions { get; set; }
}
The DbContext has:
modelBuilder.Entity<QuestionSet>()
.HasMany(c => c.Questions)
.WithMany(c => c.QuestionSets)
.Map(x => x.ToTable("QUESTION_SET_QUESTION")
.MapLeftKey("question_set_id")
.MapRightKey("question_id"))
;