When I run application I have this error:
PossibleAnswer_Question_Source: : Multiplicity is not valid in Role 'PossibleAnswer_Question_Source' in relationship 'PossibleAnswer_Question'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.
How to resolve it?
Model classes for Question and PossibleAnswer:
public class Question
{
public int ID { get; set; }
public string Text { get; set; }
public bool IsAssociatedWithProfessor { get; set; }
public bool IsAssociatedWithAssistant { get; set; }
public virtual ICollection<PossibleAnswer> PossibleAnswers { get; set; }
}
public class PossibleAnswer
{
public int ID { get; set; }
public string Text { get; set; }
public int QuestionID { get; set; }
[ForeignKey("QuestionID")]
public virtual Question Question { get; set; }
}
And I put this in OnModelCreating(DbModelBuilder modelBuilder):
modelBuilder.Entity<PossibleAnswer>()
.HasRequired(f => f.Question)
.WithRequiredDependent()
.WillCascadeOnDelete(false);
[Key]attribute toQuestion.IDproperty, or add[InverseProperty("ID")]toPossibleAnswer.Question- Lukas.Navratil[InverseProperty("PossibleAnswers ")], but it is not required when you fix the mapping and add[Key]attribute... - Lukas.Navratil