asp.net mvc 2 - reduce number of round trips - linq-to-sql -


is possible reduce number of round trips database during execution of asp.net mvc 2 action following specific case , in general? i'm using linq-to-sql. following code results in 60 selects, take 60 round trips database. how can reduce number of round trips ?

if more of code needed, post it.

my view model :

public class articlescontainerviewmodel {     public articlescontainerviewmodel()     {     }      public article categoryarticle { get; set; }      public ilist<articlesnode> categorynodes { get; set; } }  public class articlesnode {     public article nodearticle { get; set; }      public iqueryable<article> nodeitems { get; set; } } 

the view:

<ul class="tabs">         <% foreach (var category in model)            { %>         <li><a href="#" class="s">             <%= html.encode(category.categoryarticle.abbreviatedtitle) %></a></li>         <% } %>     </ul>     <!-- tab "panes" -->     <div class="panes">         <% foreach (var category in model)            {         %>         <div>             <table style="width: 100%;" cellpadding="0" cellspacing="0">                 <% int counter = 0; foreach (var node in category.categorynodes)                    {                 %>                 <%if (counter % 2 == 0)                   { %>                 <tr>                     <%} %>                     <td class="content-container">                         <div class="index-node-title">                             <%= html.encode(node.nodearticle.articletitle)%>&nbsp;<span class="small1 darkgrey2">(<%= html.encode(node.nodeitems.count().tostring())%>)</span>                         </div>                         <div class="index-node-content">                             <ul class="index-node-content-list">                                 <% foreach (var item in node.nodeitems.take(2)) 

the code little bit messy if ask me, , guess type of model of type ilist<articlescontainerviewmodel> or similar. problem using iqueryable "high" in application. structure go is:

1. first select categories , put in `viewmodel` using single query.  2. categories select articles or else db in single query, put result in dictionary category key. 

that way should able 2 queries instead of m*(n+1) having now.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -