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 (StammBelegarten item in e.NewItems) { if (fk.Where(k => k.id_Belegart == item.id).Count() == 0) { var k = new SI_BelegartenTextbausteine(); k.id_Belegart = item.id; k.id_Textbaustein = textbaustein.id; k.id_Sprache = textbaustein.id_Sprache; k.Mandantory = item.Mandantory == true ? (short)1 :(short)0; fk.Add(k); db.AddToSI_BelegartenTextbausteine(k); db.SaveChanges(); } } } break; } case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: { if (e.OldItems != null && e.OldItems.Count > 0) { foreach (StammBelegarten item in e.OldItems) { if (fk.Where(k => k.id_Belegart == item.id).Count() == 1) { var k = fk.Where(ka => ka.id_Belegart == item.id).SingleOrDefault(); fk.Remove(k); db.DeleteObject(k); db.SaveChanges(); } } } break; } default: { break; } } }