我正在设计一个测试数据库(比如说@school
),我不知道如何进行数据库播种(我使用代码优先方法,模型如下)
我的模型如下:
Levels -> Subjects -> Chapters -> Questions -> Options
如果我必须播种,我需要创建一个级别和一个主题列表,这反过来又需要章节列表,而这些章节又需要一系列问题,然后列出选项。
这是模型的代码:
//Level
public class Level
{
public Level()
{
Subjects = new List<Subject>();
}
public int id { get; set; }
public string Name { get; set; }
//Navigate
public virtual ICollection<Subject> Subjects { get; set; }
}
//Subject
public class Subject
{
public Subject()
{
Chapters = new List<Chapter>();
}
public int id { get; set; }
public string Name { get; set; }
public int LevelId { get; set; }
//Navigate
public virtual Level Level { get; set; }
public virtual ICollection<Chapter> Chapters { get; set; }
}
// Chapter
public class Chapter
{
public Chapter()
{
Questions = new List<Question>();
}
public int id { get; set; }
public string Name { get; set; }
public int SubjectId { get; set; }
public int LevelId { get; set; }
//Navigate
public virtual Subject Subject { get; set; }
public virtual Level Level { get; set; }
public virtual ICollection<Question> Questions { get; set; }
}
任何帮助将不胜感激