← Tutti gli articoli

Entity Data Framework - Delete a record through the primary key. EntityKey (namespace System.Data)

05 July 2010  ·  EDF · Article  ·  24 visite

Entity Data Framework - Delete a record through the primary key. EntityKey (namespace System.Data)

In the following block code I'll show how to delete a record in the table Tbl_SpidBustaPaga through the primary key (ID_SpidBustaPaga):

 {          
int ID_SpidBustaPaga = Convert.ToInt32(hid_ID_SpidBustaPaga.Value);
ContraEntities contraEntityCtx = new ContraEntities(ConfigurationManager.ConnectionStrings["ContraCSEntities"].ToString());
var BustaPagaKey = new EntityKey("ContraEntities.Tbl_SpidBustaPaga", "ID_SpidBustaPaga", ID_SpidBustaPaga);
var contact = contraEntityCtx.GetObjectByKey(BustaPagaKey);
contraEntityCtx.DeleteObject(contact);
contraEntityCtx.SaveChanges();
}

Si è verificato un errore imprevisto. Ricarica

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.