title: Silverlight,asynchronous,lazy loading what's the best way?
body: <p>I started to use silverlight/flex and immediately bumped into the asynchronous service calling. I'm used to solving the data access problems in an OO-way with one server fetch mechanism or another.</p>
  
  <p>I have the following trivial code example:</p>
  
  <pre><code>public double ComputeOrderTotal(Order order) 
  { 
     double total = 0;
     // OrderLines are lazy loaded
     foreach (Orderline line in order.Orderlines) 
     { 
         // Article,customer are lazy loaded 
         total = total + line.Article.Price - order.Customer.discount;
     }
     return total;
  }
  </code></pre>
  
  <p>If I understand correctly, this code is impossible in Flex/Silverlight. The lazy loading forces you to work with callbacks. IMO the simple expample above will be a BIG mess.</p>
  
  <p>Can anyone give me a structured way to implement the above ?</p>
  
  <p>Edit:</p>
  
  <ul>
  <li><strong>The problem is the same for Flex/Silverlight, pseudo code would
  do fine</strong></li>
  <li><strong>Its not really ORM related but most orms use lazy loading so i'll remove
  that tag</strong></li>
  <li><strong>The problem is lazy loading in the model</strong></li>
  <li><strong>The above example would be very doable of all data was in memory but
  we assume some has to be fetched from
  the server</strong></li>
  <li><strong>Closueres dont help since sometimes data is already loaded and no asynchronous fetch is needed</strong></li>
  </ul>