Can you explain the exact mechanism of how SaveChanges() works for entities with changed properties. For example, we have retrieved a Pencil object from the db. And we want to change its quantity from 5 to 10. Then we invoke SaveChanges(). My question is, how does EF know that the quantity of the previous state was 5 and should update it to 10? Does it keep an image of the db state, of the entity and it compares them? For example, if I set the same Pencil objects's quantity from 5 to 5 again and invoke SaveChanges(), will an update command be triggered in SQL?
Excellent explanation, thank you so much
awesome Hubert, it really help me to understand ef change tracker. thank you so much,
Such a good explanation👏
Thanks so much for this clarification
Great content!
Can you explain the exact mechanism of how SaveChanges() works for entities with changed properties.
For example, we have retrieved a Pencil object from the db. And we want to change its quantity from 5 to 10. Then we invoke SaveChanges().
My question is, how does EF know that the quantity of the previous state was 5 and should update it to 10? Does it keep an image of the db state, of the entity and it compares them?
For example, if I set the same Pencil objects's quantity from 5 to 5 again and invoke SaveChanges(), will an update command be triggered in SQL?
It doesn't MSDN states that it runs an update SQL statement unless the entity has a null PK in which case it inserts.
thank you
thanks sir.. so if i want to update, i need an tracked entity?