DbSet.Attach(entity) vs DbContext.Entry(entity).State = EntityState.Modified

asked10 years ago
last updated3 years ago
viewed123.1k times
Up Vote147Down Vote

When I am in a detached scenario and get a dto from the client which I map into an entity to save it I do this:

context.Entry(entity).State = EntityState.Modified;
context.SaveChanges();

What is the DbSet.Attach(entity) used for then? or why should I use the .Attach method when EntityState.Modified already attaches the entity?