コード例 #1
0
 void Initialize()
 {
     using (var db = new RabbitDatabaseEntities())
     {
         rabbit = db.RabbitTable.ToList();
     }
     //display rabbits
 }
コード例 #2
0
        private void ListViewRabbits_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (rabbit != null)
            {
                using (var db = new RabbitDatabaseEntities())
                {
                    //find in the database the rabbnit which has an ID the same as the selected rabbit
                    var rabbitToDelete = db.RabbitTable.Find(showrabbitdata.RabbitTableId);

                    var result = MessageBox.Show($"Delete Rabbit{rabbitToDelete.RabbitTableId}? Confirm", "Warning", MessageBoxButton.YesNoCancel);
                    if (result == MessageBoxResult.Yes)
                    {
                        db.RabbitTable.Remove(rabbitToDelete);
                        db.SaveChanges();
                        ListViewRabbits.ItemsSource = null;   //set to zero
                        rabbit = db.RabbitTable.ToList();     //refresh rabbits
                        ListViewRabbits.ItemsSource = rabbit; //refresh view
                    }
                }
            }
        }