public void Save_Click(object sender) { if (_contact.State == EntityState.Added) { ContactdbContext.contacts.Add(_contact); } _contact.IsSelected = true; IEnumerable <DbEntityValidationResult> validationresult = ContactdbContext.GetValidationErrors(); if (validationresult.Count() == 0) { try { ContactdbContext.SaveChanges(); } catch (Exception ex) { throw ex; } crud_modal.Children.Clear(); crud_modal.Visibility = System.Windows.Visibility.Collapsed; contactComboBox.Text = _contact.name; } else { MessageBox.Show("error"); } }