Entity Framework Remove vs State.Deleted

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

Question

Plain and simple, is there any difference between

DbSet().Remove(x)

to

context.Entry(x).State = State.Deleted?

Thanks

1
1
2/15/2016 10:32:04 PM

Accepted Answer

Not that I can tell, the MSDN article for Remove says

Marks the given entity as Deleted such that it will be deleted from the database when SaveChanges is called. Note that the entity must exist in the context in some other state before this method is called.

.Remove is likely just the preferred way to remove items.

EDIT:

Also, the MSDN article for the EntityState says this for deleted.

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.

Which just further solidifies that they are effectively the same thing.

2
2/15/2016 10:38:23 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