user5326354
user5326354

Reputation:

Entity Framework Detach vs Remove

Can someone explain what is the difference between those two? When is it better to use each of these methods and why?

Upvotes: 2

Views: 2222

Answers (1)

tede24
tede24

Reputation: 2354

  • Remove: mark the entity to be deleted so when you do SaveChanges it's deleted from the db
  • Detach: remove the entity from the DbContext change tracker so whatever you do with the entity DbContext doesn't notice. So when you do SaveChanges nothing happens with this entity

Upvotes: 2

Related Questions