I have an app where students can sign up for school courses. To prepare for their attendance information, I need data in the Attendance table to be populated. I would typically accomplish this task like this:
Attendance newAttendace = new Attendance
{
CourseID = course.CourseID,
StudentID = thisStudent.StudentID,
AttendanceDay = 1,
Present = false
};
db.Attendance.Add(newAttendance);
db.SaveChanges();
But I need to do this for every possible attendance day that the course has - so if there are 20 days that students will attend this course, I need to be able to add rows where AttendanceDay = 1 through 20.
I am thinking of doing this within a for loop and increasing Attendanceday 1 over and over and adding "newAttendance" to the database all 20 times then doing the db.SaveChanges() call - but I've never done a for loop while entering database entries before - is there a more elegant way of doing this within ASP.NET MVC with C#?