private static void CreateNewStudent(StudentSystemContext db, string newStudentName, string newStudentNumber) { var newStudent = new Student() { Name = newStudentName, Number = newStudentNumber }; db.Students.Add(newStudent); db.SaveChanges(); }
public static void Main() { using (var db = new StudentSystemContext()) { //CreateSampleData(db); IQueryable query = from c in db.Courses select c.Name; foreach (var item in query) { Console.WriteLine(item); } } }
static void Main(string[] args) { var db = new StudentSystemContext(); using (db) { CreateNewStudent(db, "Georgi Jivkov", "094276"); CreateNewStudent(db, "Kiril Ivanov", "042758"); CreateNewStudent(db, "Dragomir Ivanov", "084868"); var allStudents = from s in db.Students select s; foreach (var student in allStudents) { Console.WriteLine(student.Name); } } }
private static void CreateSampleData(StudentSystemContext db) { var student = new Student() { StudentId = 1, Name = "Georgi Ivanov", Number = 2000, DateOfBirth = new DateTime(1994, 01, 16) }; var course = new Course() { Name = "HQC", Description = string.Empty, Materials = "SOLID, Design Patterns" }; var homework = new Homework() { HomeworkId = 1, CourseId = "HQC", StudentId = 1, Course = course, Student = student, DateSent = new DateTime(2015, 10, 10) }; student.Courses.Add(course); student.Homeworks.Add(homework); course.Students.Add(student); course.Homeworks.Add(homework); db.Courses.Add(course); db.Homeworks.Add(homework); db.Students.Add(student); db.SaveChanges(); }