Я новичок в .NET MVC, и мне трудно использовать Code First с существующей базой данных, в которой в таблице есть один к одному или нет ( 1 -> 0..1) отношения.
У меня есть отчет, в котором может быть много разделов, и в каждом разделе может быть много вопросов. А теперь я думаю, что у меня проблемы ... на каждый вопрос может быть один ответ или ни одного.
Я получаю следующую ошибку:
System.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. но я не думаю, что это причина ошибки.
Любая помощь приветствуется.
Спасибо.