0

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?

Atul
  • 440
  • 8
  • 24

1 Answers1

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