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 (SI_Events item in e.NewItems) { if (fk.Where(k => k.id_Event == item.id).Count() == 0) { var k = new SI_SelectedEvents(); k.id_Event = item.id; //k.Firmen_Personen = CurrentPerson; fk.Add(k); db.AddToSI_SelectedEvents(k); db.SaveChanges(); } } } break; } case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: { if (e.OldItems != null && e.OldItems.Count > 0) { foreach (SI_Events item in e.OldItems) { if (fk.Where(k => k.id_Event == item.id).Count() == 1) { var k = fk.Where(ka => ka.id_Event == item.id).SingleOrDefault(); fk.Remove(k); db.DeleteObject(k); db.SaveChanges(); } } } break; } default: { break; } } }