static void Main(string[] args) { using (var context = new SchoolDbContext()) { var newStudent = CreateNewStudent(context); var newScheduledCourse = CreateNewScheduledCourse(context); newScheduledCourse.Students.Add(newStudent); newStudent.ScheduledCourses.Add(newScheduledCourse); context.SaveChanges(); } Console.WriteLine(); Console.WriteLine("Press any key to exit."); Console.ReadKey(); }