void AddOrUpdateTeacher(EncyclopediaContext context, string TrackName, string TeacherName) { var crs = context.Tracks.SingleOrDefault(c => c.TrackName == TrackName); var inst = crs.Teachers.SingleOrDefault(i => i.LastName == TeacherName); if (inst == null) { crs.Teachers.Add(context.Teachers.Single(i => i.LastName == TeacherName)); } }