views:

21

answers:

1

I don't follow:

 var refreshedSched = newTicket.Schedules
     .FirstOrDefault(s => CompareSchedules(s, sched));

 if (refreshedSched != null)
 {
      if (refreshedSched.ScheduleExtension == null)
           refreshedSched.ScheduleExtension = new ScheduleExtension();

      refreshedSched.ScheduleExtension.RTUpdateCurrent 
           = sched.ScheduleExtension.RTUpdateCurrent;
 }

Schedule and ScheduleExtension have a One to One association on Schedule.ID=ScheduleExtension.ScheduleID, and when I try to assign a new ScheduleExtension to a Schedule it wants to change the Schedule's ID column to 0...

Why would it do that?

+1  A: 

The association direction is important. I had accidentally made ScheduleExtension the Parent entity, and Schedule the Child. So when you do any assignment, no matter what direction, it sets the Child property to the value of the Parent property in the association.

Reversing the association so that Schedule is the parent correctly sets the ScheduleID of the ScheduleExtension to the Schedule's ID.

Telos