I recently noticed there is two different ways to delete an entry from the DB in Entity Framework.
I had originally implemented it using the following
db.Courses.Remove(course);
But then I found out that you can also do the following
db.Entry(course).State = EntityState.Deleted;
Is there any difference between the two?
The only reason I can think for me to switch to the latter would be to be more consistent in my implementation since that’s the approach I use to edit entries.
Any thoughts ?
Both methods mark the entity as deleted, so the next db.SaveChanges(); removes them from the database and the context.
This article describes all ways you can add, modify and delete entities.
http://msdn.microsoft.com/en-us/library/gg696174(v=vs.103).aspx