Note that there are some explanatory texts on larger screens.

plurals
  1. POGrouped preloading of database items in ASP.Net MVC
    primarykey
    data
    text
    <p>Imagine you have a <code>View</code> within ASP.Net MVC which have got several Partial Views embedded in it which work independently and each load their own model through <code>Html.Action</code> (Child Actions). Now each separate Partial View would need to load certain items from the database. In terms of performance it would be much more efficient to group all such database calls together and preload all the items of the same type with one query rather than one by one through each separate Child Action.</p> <p>For example, lets say we have the following structure:</p> <ul> <li>Index (View) <ul> <li>Main Menu (Child Action / Partial View) <ul> <li>This would load Sections with IDs 1 &amp; 2</li> </ul></li> <li>Main Content (Child Action / Partial View) <ul> <li>This would load Sections with IDs 3, 4, &amp; 5</li> </ul></li> <li>Related Sections (Child Action / Partial View) <ul> <li>This would load Sections with IDs 6 &amp; 7</li> </ul></li> <li>...</li> </ul></li> </ul> <p>Now in the above scenario, each child action above would separately make the respective database calls to load the sections required by its own model. </p> <p>In order to improve on performance, we need a way whereby before we execute each Action or Child Action, such database item requests are 'registered' and then be able to load all the items together. Then when the Action or Child Action would need to use such database items, they would have already been preloaded altogether.</p> <p>We were thinking of using Action Filters which are attached to each Action &amp; Child Action stating which items are requested but unfortunately the <code>OnActionExecuting</code> method is called separately prior to each action being call.</p> <p>We would like something similar to Action Filters but rather than being executed prior to each call, they are executed all in the beginning of the request before any Action / Child Action is called. This way we can register all such database item requirements and load them together.</p> <p>Something similar to the <code>OnInit</code> event within Asp.Net Web Forms whereby first the OnInit for all user controls &amp; controls is called followed by the other events within the ASP.Net Web Forms life cycle.</p> <hr> <p>Or maybe you can offer a different solution which performs similarly to what we require?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload