I am coding a MVC 5 internet application with EF6 and I have a question about what happens when the context.SaveChanges() method is called.
Does the DbContext object store the CRUD actions that occur, such that if the SaveChanges() method is called, and none of the data in the database is updated, no action occurs?
Here is an example:
In the above example, are any changes made to the database? Do any database transactions occur?
I have done some research, but could not find the answer to this question.
Thanks in advance.
EF6 uses the change tracker to detect if there are any changes.
When you do a call to SaveChanges(), one of the first things EF6 is doing is calling DetectChanges() which will inspect the change tracker.
Now suppose you really want to know if something has changed you can look in the changetracker yourself too. This post shows how in the answer :
Entity Framework 6: audit/track changes
No, if entitys are not changed, it's state is unchanged, so EF is not interested in those.
You can force saving by changing state of entity manualy if required.