void UpdateCollection(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { switch (e.Action) { case System.Collections.Specialized.NotifyCollectionChangedAction.Add: { if (e.NewItems != null && e.NewItems.Count > 0) { foreach (person item in e.NewItems) { if (fk.Where(k => k.id_Teilnehmer == item.id).Count() == 0) { var k = new Termine_TeilnehmerSI(); k.id_Teilnehmer = item.id; k.CRMTermine = CurrentTermin; fk.Add(k); db.AddToTermine_TeilnehmerSI(k); // db.SaveChanges(); } } } break; } case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: { if (e.OldItems != null && e.OldItems.Count > 0) { foreach (person item in e.OldItems) { if (fk.Where(k => k.id_Teilnehmer == item.id).Count() == 1) { var k = fk.Where(ka => ka.id_Teilnehmer == item.id).SingleOrDefault(); fk.Remove(k); db.DeleteObject(k); // db.SaveChanges(); } } } break; } default: { break; } } }