Reputation: 2774
I am trying to figure out how to turn off caching of the DbContext using the repository pattern. Right now my view and CRUD functions use the same context, so putting .AsNoTracking() on the DbSet is not working because updating the data is not happening as it did before.
_context.Entry(e).State = e.Id == 0 ? EntityState.Added : EntityState.Modified;
_context.SaveChanges();
Can someone explain caching in EntityFramework, so that I can provide dynamic functionality where if a user updates a record and then they click a link to view other data, then the data represented on the new grid takes in to effect the change from the previous controller action...hope that makes since.
View Orders -> Update Order -> Save Order -> View Users -> View correctly shows Item count aggregate based off of order changes.
Upvotes: 2
Views: 5215
Reputation: 17589
Question you are asking is not really easy. what you would do depends on what type of entities you are using as you probably know there are several generic options - EF entities, Self Tracking entities, POCO no proxy, POCO with proxy depending on what you have you would either
1) reattach entity, call Load
on navigation property of entity
2) reattach entity, call LoadProperty
on context
3) just call either Load / LoadProperty if the context remain the same
What you refer as caching in fact is entity tracking , so you can turn it off either detaching entities or setting MergeOption
to MergeOption.NoTracking
on ObjectQuery
Upvotes: 1