Я новичок в .NET MVC и пытаюсь использовать Code First с существующей базой данных, в которой таблица имеет отношение один к одному или один (1 -> 0..1).
У меня есть отчет, который может иметь много разделов, и у каждого раздела может быть много вопросов.Вот немного того, что мне кажется, что у меня проблемы ... на каждый вопрос может быть один ответ или нет.
Я получаю следующую ошибку:
Система.Data.Edm.EdmAssociationEnd:: Кратность недопустима в роли 'QuestionAnswer_Question_Source' в отношении 'QuestionAnswer_Question'.Поскольку свойства зависимой роли не являются ключевыми свойствами, верхняя граница кратности зависимой роли должна быть � * �.
Вот мои классы моделей:
ModeratorReport.cs
public class ModeratorReport
{
[Key, Column(Order = 0)]
public int ModeratorReportID { get; set; }
[Key, Column(Order = 1)]
public string Status { get; set; }
public string FileYear { get; set; }
public string SessionCode { get; set; }
public string CentreNumber { get; set; }
public string SubjectNumber { get; set; }
public string PaperNumber { get; set; }
public string ModeratorNumber { get; set; }
public DateTime? DateModified { get; set; }
public virtual ICollection<AuditItem> Audit { get; set; }
}
Section.cs
public class Section
{
[Key]
public int SectionID { get; set; }
public string SectionEnglish { get; set; }
public string SectionWelsh { get; set; }
public virtual ICollection<Question> Questions { get; set; }
}
Question.cs
public class Question
{
[Key]
public int QuestionID { get; set; }
[ForeignKey("Section")]
public int SectionID { get; set; }
public string QuestionEnglish { get; set; }
public string QuestionWelsh { get; set; }
public string Type { get; set; }
public virtual Section Section { get; set; }
public virtual QuestionAnswer QuestionAnswer { get; set; }
}
QuestionAnswer.cs
public class QuestionAnswer
{
[Key]
public int AnswerID { get; set; }
[ForeignKey("ModeratorReport"), Column(Order = 0)]
public int ModeratorReportID { get; set; }
[ForeignKey("ModeratorReport"), Column(Order = 1)]
public string Status { get; set; }
[ForeignKey("Section")]
public int SectionID { get; set; }
[ForeignKey("Question")]
public int QuestionID { get; set; }
public string Answer { get; set; }
public virtual ModeratorReport ModeratorReport { get; set; }
public virtual Section Section { get; set; }
public virtual Question Question { get; set; }
}
У меня также есть отношения один-ко-многим с ModeratorReport и Audit, но я не думаю, что это является причиной ошибки.
Буду признателен за любую помощь.
Спасибо.