Reputation: 10068
As in the title, I have a method:
void method(MyDb db, Thread thread, Post post)
{
thread.Title = "changed";
db.SaveChanges();
}
(of course thread item is within MyDb object)
How does it recognize items that need to be updated? I didn't specify anywhere anything like db.Update(thread)
or anything like that, it knew what to update without my help. What mechanisms are under it?
Upvotes: 1
Views: 103
Reputation: 364279
When you load entity Thread
from database it becomes by default "attached". It means EF internally keep reference to your entity and it also keeps original values of the entity when you loaded it from the database.
When you updated a title there may be two scenarios:
SaveChanges
SaveChanges
You can read more about that process here.
Upvotes: 3