Reputation: 8944
In reading an article on N-Tiered Applications, I came across information regarding concurrency tokens and change tracking information:
Another important concept to understand is that while the default-generated entities support serialization, their change-tracking information is stored in the ObjectStateManager (a part of the ObjectContext), which does not support serialization.
My question is three-fold:
DbContext
?Repository
class within a using
statement, does closing the database connection when the program leaves the using
statement get rid of any option for change tracking?Upvotes: 0
Views: 254
Reputation: 364249
DbContext
is just wrapper around ObjectContext
and it exposes change tracking information through ChangeTracker
property (returns DbChangeTracker
) and for particular entity through calling Entry
method (returns DbEntityEntry<T>
).SaveChanges
. It tracks changes you did on your entities since you loaded them into current context instance. Concurrency token resolves optimistic concurrency in the database => it validates that another process / thread / user / context instance didn't change the same record your context is going to modify during SaveChanges
.Upvotes: 1