.NET MVC - Storing database result during single page result?
- by ropstah
Fairly simple issue which is solved in PHP by using a static variable.
private static $pages;
public function Pages() {
if($pages == null) {
$pages = new PageCollection();
$pages->findAll();
}
}
Everywhere in my code I use Pages()::someFindFunction() to make sure the results are fetched only once, and I use that same collection.
I want the same in my .NET MVC application: use something like:
<%=MySite.Pages.findById(1).Title%>
In the code below, if I use a private variable, or if I use a public class with shared variables (doesn't matter) they are both persisted during the entire application.
I want them to load the same way PHP does, once per request. Now where do I store the .NET equivalent of private static $pages, so that the code below works?
//what to do with $pages??
Public Module MySite
Public Function Pages() As PageCollection
If $pages Is Nothing Then
$pages.loadAll()
End If
Return $pages
End Function
End Module