EF Code First 中的多对多关系表示
我正在尝试以以下方式开发一个结构......
- 我代表由教师教授的课程。
- 对于每门课程都有任意数量的考试(因为考试是随机生成的,每一代都算作不同的考试),我必须在数据库中跟踪它。
- 考试可由 0 名或更多学生参加。 (相反,学生可以参加一项或多项考试。)
- 一旦学生参加考试(通过我已经开发的网络界面完成),该学生就会收到考试分数和考试状态(通过) ,失败,重考,测试等)
- 还有一些其他“东西”我没有提到,例如考试由问题组成(由老师创建)等,但我有很好的理解的。
我几乎已经完成了我的结构,但我正在努力解决如何表示学生与考试的关系以及如何处理考试状态。到目前为止,这是我的想法。 (已经很晚了,所以我对愚蠢的错误表示歉意。)
public class Student
{
public string StudentID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
// Should this even be part of the Student POCO?
public virtual ICollection<Exam> ExamsTaken { get; set; }
}
// I know this is right - putting it here to provide all the classes in question.
public class ExamStatus
{
public int ExamStatusID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
// This is the POCO that really hangs me up.
public class Exam
{
public int ExamID { get; set; }
public int CourseID { get; set; }
public string ExamTitle { get; set; }
// Not sure if this should be part of Exam, or part of a different
// object?
public decimal? Score { get; set; }
public int? ExamStatusID { get; set; }
public virtual ICollection<Question> Questions { get; set; }
public virtual Course Course { get; set; }
public virtual ExamStatus ExamStatus { get; set; }
}
我将不胜感激对这种多对多关系(学生<->考试)的任何帮助。我想我想得太多了,并且对一些可能相当简单的事情彻底感到困惑。
I am trying to develop a structure in the following manner...
- I am representing Courses which are taught by Teachers.
- For each of those Courses there are any number of Exams (because the Exam is randomly generated, each generation counts as a different exam), and I have to track that in the database.
- An Exam can be taken by 0 or more Students. (And, conversely, a Student can have taken one or more Exams.)
- Once the Student takes the exam (which is done via a web interface that I have already developed), that Student receives a score for the Exam and an ExamStatus (Passed, Failed, Retake, TestOut, etc.)
- There are some other "stuff" in there that I didn't address such as Exams are made up of Questions (which are created by the Teacher), etc, but I have a good understanding of that.
I have almost finished my structure, but I am struggling with how to represent the relationship of Students to Exams and also working the ExamStatus. Here is my thought so far. (It is late, so my apologies for stupid errors.)
public class Student
{
public string StudentID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
// Should this even be part of the Student POCO?
public virtual ICollection<Exam> ExamsTaken { get; set; }
}
// I know this is right - putting it here to provide all the classes in question.
public class ExamStatus
{
public int ExamStatusID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
// This is the POCO that really hangs me up.
public class Exam
{
public int ExamID { get; set; }
public int CourseID { get; set; }
public string ExamTitle { get; set; }
// Not sure if this should be part of Exam, or part of a different
// object?
public decimal? Score { get; set; }
public int? ExamStatusID { get; set; }
public virtual ICollection<Question> Questions { get; set; }
public virtual Course Course { get; set; }
public virtual ExamStatus ExamStatus { get; set; }
}
I would appreciate any help with this many-to-many relationship (Students <-> Exams). I think I've thought about it too much and have thoroughly confused myself on something that is probably fairly straightforward.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我要改变的。我不认为这正是亚当所说的。如果是的话请告诉我,我会删除该帖子
This is what I would change. I don't THINK its exactly what Adam said. If it is let me know and i'll remove the post
考试与考试结果是分开的。
因此,将分数和状态提取到单独的表中。状态字段可能还希望包含已采取或待处理的内容,以便您知道他们已采取但正在等待分数(也就是说,除非全部自动完成),
这样学生就有了已采取的考试列表,该列表是链接的到分数表,分数表链接到它是哪次考试。
The exam is seperate to an exam result.
Hence pull out the scores and status to a seperate table. The status field may also want to include a taken or pending, so that you know they have taken it but it is awaiting marks (that is unless it is all done automatically)
That way a student has a list of exams taken, which is linked to the score table and the score table is linked to which exam it was.