private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { var person = this.ListBox.SelectedItem as Person; if (person == null) { person = new Person { BirthDate = this.BirthDateTextBox.Text, FirstName = this.FirstNameTextBox.Text, LastName = this.LastNameTextBox.Text }; this.ListBox.Items.Add(person); } else { person.FirstName = this.FirstNameTextBox.Text; person.LastName = this.LastNameTextBox.Text; person.BirthDate = this.BirthDateTextBox.Text; } using (var context = new PersonContext()) { context.Persons.AddOrUpdate(person); context.SaveChanges(); } }
public MainWindow() { InitializeComponent(); using (var context = new PersonContext()) { var dbSet = context.Persons.ToList(); foreach (var person in dbSet) { this.ListBox.Items.Add(person); } } }