/// <summary> /// Save all changes, for learning the number of changes /// are shown in the IDE Output window, if there were changes /// and the result is zero there is an issue if there are no /// exceptions thrown prior to this save operation. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveAllChangesButton_Click(object sender, EventArgs e) { try { Console.WriteLine(context.SaveChanges()); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Save all changes, for learning the number of changes /// are shown in the IDE Output window, if there were changes /// and the result is zero there is an issue if there are no /// exceptions thrown prior to this save operation. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveAllChangesButton_Click(object sender, EventArgs e) { Console.WriteLine(context.SaveChanges()); try { //context.Customers.Add(new Customer()); } catch (DbEntityValidationException dbEx) { foreach (var entityErr in dbEx.EntityValidationErrors) { Console.WriteLine($@"Entity of type ""{entityErr.Entry.Entity.GetType().Name}"" in state ""{entityErr.Entry.State}"" has the following validation errors:"); foreach (var error in entityErr.ValidationErrors) { Console.WriteLine($@"- Property: ""{error.PropertyName}"", Value: ""{entityErr.Entry.CurrentValues.GetValue<object>(error.PropertyName)}"", Error: ""{error.ErrorMessage}"""); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }