i have a Model like so
public class School{
public int Id {get;set;}
public string Name {get;set;}
static private IEnumerable<School> school;
static public IEnumerable<School> Schools(ContextDb context){
if(school != null)
return school;
return(school = context.Schools.ToList());
}
}
Now I have a page that inserts data into the table, using ajax. The problem is when the popup closes, I would regenerate the Academy.Schools again but since the “school” variable is not null (or is cached) it would return the previous data and not the refreshed data (with the newly added record.
With that said, how do i empy that private variable so I would trigger the “return(school = ..);” line in the class?
Thanks!!
Your Model design is very strange (based on the given information it’s hard to offer a better one, is is some kind of ActiveRecord pattern?), but with the current design you need a new method which empties the “cache” e.g. set
schooltonull:After calling
School.InvalidateSchoolsthe subsequent call toSchool.Schoolswill return the new data.