private void dataGridView1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Delete) { if (MessageBox.Show("Do you really want to delete selected row?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { using (var db = new SchoolEntities()) { db.DeletePerson(dataGridView1.Rows.Count); db.SaveChanges(); dataGridView1.DataSource = db.Person.ToList(); } } } }
public void UsingStoredProcedureOnContext() { using (new TransactionScope()) using (var context = new SchoolEntities()) { context.DeletePerson(1); } }