Hello
I have this code:
Schedule s = _entities.Schedules.Where(x => x.ScheduleID == schedule.ScheduleID && x.BookingObject.BookingObjectID == bookingObjectID).FirstOrDefault();
if(s == null)
s = new Schedule();
s.ScheduleStart = schedule.ScheduleStart;
s.ScheduleEnd = schedule.ScheduleEnd;
foreach (var t in schedule.Timetables)
{
s.Timetables.Add(t);
}
_entities.AddToSchedules(s);
_entities.SaveChanges();
Exception: System.InvalidOperationException
the object schedule gets passed in as a parameter
EDIT:
changed to:
Schedule sh = new Schedule();
sh.ScheduleStart = schedule.ScheduleStart;
sh.ScheduleEnd = schedule.ScheduleEnd;
foreach (var t in schedule.Timetables)
{
//sh.Timetables.Add(t); // doesn't work
sh.Timetables.Add(new Timetable { DayOfWeek = t.DayOfWeek, StartTime = t.StartTime, EndTime = t.EndTime }); // works
}
_entities.AddToSchedules(sh);
_entities.SaveChanges();
is there some logical reason why sh.Timetables.Add(t) doesn't work since its a collection of Timetable?
/M