title: nested foreach loops and WCF RIA domain service
body: <p>I am attempting to load a table of shape coordinates out of a database for plotting on a silverlight bing map, The table structure I am interested in is here <a href="http://dl.dropbox.com/u/10440538/ADO.png" rel="nofollow">http://dl.dropbox.com/u/10440538/ADO.png</a>. </p>
  
  <p>Using a wcf ria service I can load the data ok, but I need help with my code to pull out the lowest level data (the coordinates) and separate them into collections. The end result should be so that I have a collection of LocationCollections, one LocationCollection for each mapshape in the database.</p>
  
  <p>This is my loadoperation callback</p>
  
  <pre><code>    void FarmsLoaded(LoadOperation&lt;Farm&gt; loadOp) {
  
          LocationCollection lc = new LocationCollection();
  
          foreach (Farm f in loadOp.Entities) {
              foreach (FarmLocation fl in f.FarmLocations) {
                  foreach (MapShape ms in fl.MapShapes) {
                      lc.Clear();
                      foreach (MapPoint mp in ms.MapPoints) {
                          lc.Add(new Location(mp.Latitude, mp.Longitude));
                      }
                      shapeList.Add(lc);   //observablecollection of LocationCollections
                  }
              }
          }
      }
  </code></pre>
  
  <p>shapeList is then bound to a map layer. Unfortunately when I run this only the last mapshape in the db is drawn. I think I misunderstand how the foreach nesting is being traversed so I'd appreciate any effort at enlightenment on correct use of nested foreach in this situation, or any alternate suggestions if foreach is not appropriate (LINQ?)</p>