I am new to Entity Framework.
I have get to some values in my database using EF. It returns perfectly, and the values are shown in labels. But When I delete all values in my table (without using EF), the EF query is returning my old values. I know the EF stores the values in cache and returns the cached data for subsequent runs. Is this correct?
So how can I solve the problem when I have deleted all values in my database, but EF returns the old values?
Edit:
Now i used datamodel.SaveChanges()
. But now it's return same old values.
My sample query is look like 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();
}
I think you should follow some of the other solutions here, but it seems like you're wanting to clear the cache. You can achieve this by doing the following:
A careful answer:
https://stackoverflow.com/a/3653392/1863179
Couple things you can do.
I think what you need is
GetDatabaseValues()
. It is used like:Information below is from msdn: