C# Entity Framework Basics CRUD Operations Updating Entities

saikiran maddukuri
saikiran maddukuri
17,903 Points

What is the use of Attach?

James Churchill in order to update the ComicBooks you used

context.ComicBooks.Attach(comicBook);
context.Entry(comicBook).State=EntityState.Modified;
context.Entry(comicBook).Property("IssueNumber").IsModified=false;
context.SaveChanges();

works in the same way as this snippet

context.Entry(comicBook).State=EntityState.Modified;
context.Entry(comicBook).Property("IssueNumber").IsModified=false;
context.SaveChanges();

both works in exactly same way so i don't find the use of Attach can any one explain the use of Attach?