c# delete entity object from client program - northwind db example

private void Sil()
{
if (this.dataGridView1.SelectedCells.Count < 1) { MessageBox.Show("Silinecek Kayıt Seçilmelidir"); return; }
string custID = this.dataGridView1.SelectedRows[0].Cells["CustomerID"].Value.ToString();

NorthwindEntities context = GetNe();
try
{
var delCust = (from cst in context.Customers
where cst.CustomerID == custID
select cst).Single();
context.DeleteObject(delCust);
context.SaveChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + Environment.NewLine + ex.InnerException);
return;
}
//.......................
BilgileriGetir();
//.......................
}



Yorumlar