I was deleting an Entity based on it’s primary key, then I made my repository generic. Here’s my current delete method:
public void Del(E entity) // where E : EntityObject on the class
{ if( entity != null)
DC.DeleteObject( entity);
return;
}
It’s running in a MVC 2 web application. So, the users send up primary key values from an Entity to delete, I create a new entity then ship it to the Delete method. This would extract the primary key and delete the item using a Where() clause. It just seems silly to query the database first.
On EF 4 you don’t need to query the object to delete (or update) but you need to set the primary key and attach it to your context. Your method would look like this:
Edit: