c# - Entity Framework Caching Issue -
i new entity framework.
i have values in database using ef. returns perfectly, , values shown in labels. when delete values in table (without using ef), ef query returning old values. know ef stores values in cache , returns cached data subsequent runs. correct?
so how can solve problem when have deleted values in database, ef returns old values?
edit:
now used datamodel.savechanges()
. it's return same old values.
my sample query below:
schoolbriefcaseentities datamodel = new schoolbriefcaseentities(); datamodel.savechanges(); list<compliance> compliance=new list<compliance>(); ilist<compliancemodel> compliancemodel; if (httpcontext.current.user.isinrole("superadmin")) { compliance = datamodel.compliances.where(c => c.school.districtid == districtid).tolist(); }
if know changes happened outside of ef , want refresh ctxt specific entity, can call objectcontext.refresh
datamodel.refresh(refreshmode.storewins, orders);
if seems common occurance, should disable object caching in queries:
schoolbriefcaseentities datamodel = new schoolbriefcaseentities(); datamodel.tblcities.mergeoption = mergeoption.notracking;
or turn off object level caching specific entity,
context.set<compliances>().asnotracking();
Comments
Post a Comment