Suppose we have some tables having Primary Key named "id". Is it possible to create only one method which gets table name and id to delete the record?
Asked
Active
Viewed 58 times
0
-
Please include more details about your problem, and include the code you've written so far. – kdbanman Oct 26 '15 at 17:07
-
http://stackoverflow.com/questions/12742473/most-efficiently-handling-create-update-delete-with-entity-framework-code-firs – Steve Greene Oct 26 '15 at 17:07
1 Answers
2
public bool Delete<E>(E entity) where E : class
{
DataContext.Entry(entity).State = System.Data.EntityState.Deleted;
DataContext.SaveChanges()
}
With Generic definition of a method you can , as done above.
Deleting a record using entity framework is by marking entity state of an object as deleted.
more on this here : https://stackoverflow.com/a/12742919/1018054
Hope that helps ! :)

Community
- 1
- 1

Vishal Sharma
- 2,773
- 2
- 24
- 36