// create database entry private void createUser(object e) { using (var context = new AccountContext()) { var account = new Account(this.Name, this.stack); context.accounts.Add(account); try { context.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var errors in ex.EntityValidationErrors) { foreach (var validationError in errors.ValidationErrors) { string errorMessage = validationError.ErrorMessage; Debug.WriteLine(errorMessage); } } } // refresh list of Accounts from db this.getUsers(); } }
// retrieve existing Accounts from db private void getUsers() { using (var context = new AccountContext()) { Accounts = context.accounts.ToList(); } }