How can I remove a record using its primary key in Entity Framework?

entity-framework

Question

How can I remove a record using its primary key without first loading the entity with a SELECT statement?

1
13
12/5/2011 8:36:31 PM

Popular Answer

Dummy objects may be used:

var entity = new YourEntity { Key = yourKey };
context.Entities.Attach(entity);
context.Entities.DeleteObject(entity);
context.SaveChanges();
20
12/5/2011 8:55:18 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow