Entity Framework Detach vs Remove

c# ef-code-first entity-framework-6

Question

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

1
2
2/14/2016 1:11:16 PM

Accepted Answer

  • 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
2
2/14/2016 9:21:50 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