Question about EF EntityState

So I was wondering about what actually happens when I delete a row using EF.

Consider the below delete:

 public void Delete(int id) { User user = db.Users.Find(id); if (user != null) { db.Entry(user).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); } } 

In my curiousity I went and looked at what the description for EntityState.Deleted which is:

The entity is being tracked by the context and exists in the database, but has been marked for deletion from the database the next time SaveChanges is called.

I'm still not clear though, does this mean that the entity isn't actually removed from the database, but rather marked as deleted so that it doesn't show up in query results?

by ortund via /r/csharp

Leave a Reply