title: Silverlight RIA many to many not working
body: <p>I am trying to get a many to many relationship working in RIA/Silverlight, but I can't seem to figure out how.</p>
  
  <p>My database looks like this...</p>
  
  <pre><code>Stores     Parts      StoreParts
  --------   -------    ----------
  ID         ID         StoreID
  StoreName  PartName   PartID
  </code></pre>
  
  <p>I create a Entity Data Model on this database.</p>
  
  <p>My XAML looks like this</p>
  
  <pre><code>&lt;toolkit:Accordion Background="White" BorderThickness="1" Height="503" HorizontalAlignment="Left" Margin="207,32,0,0" Name="accordion2" SelectionMode="ZeroOrMore" VerticalAlignment="Top" Width="181"&gt;
      &lt;toolkit:Accordion.ContentTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;ListBox BorderThickness="0" ItemsSource="{Binding Parts}"&gt;
                  &lt;ListBox.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;TextBlock Text="{Binding PartName}" /&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ListBox.ItemTemplate&gt;
              &lt;/ListBox&gt;
          &lt;/DataTemplate&gt;
      &lt;/toolkit:Accordion.ContentTemplate&gt;
      &lt;toolkit:Accordion.Effect&gt;
          &lt;DropShadowEffect BlurRadius="8" /&gt;
      &lt;/toolkit:Accordion.Effect&gt;
      &lt;toolkit:Accordion.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;StackPanel&gt;
                  &lt;TextBlock Text="{Binding StoreName}" /&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
      &lt;/toolkit:Accordion.ItemTemplate&gt;
  &lt;/toolkit:Accordion&gt;
  </code></pre>
  
  <p>My XAML code behind:</p>
  
  <pre><code>StoreContext storeContext = new StoreContext();
  accordion2.ItemsSource = storeContext.Stores;
  storeContext.Load(storeContext.GetStoresQuery());
  </code></pre>
  
  <p>My RIA DomainService:</p>
  
  <pre><code>[EnableClientAccess()]
  public class StoreService : LinqToEntitiesDomainService&lt;MenuTemp2Entities&gt;
  {
      public IQueryable&lt;Store&gt; GetStores()
      {
          return this.ObjectContext.Stores.Include("Parts");
      }
  }
  </code></pre>
  
  <p>And, finally, my RIA metadata</p>
  
  <pre><code>[MetadataTypeAttribute(typeof(Store.StoreMetadata))]
  public partial class Store
  {
      internal sealed class StoreMetadata
      {
          // Metadata classes are not meant to be instantiated.
          private StoreMetadata()
          {
          }
  
          public int ID { get; set; }
  
          [Include]
          [Association("StoreParts", "ID", "ID")]
          public EntityCollection&lt;Part&gt; Parts { get; set; }
  
          public string StoreName { get; set; }
      }
  }
  </code></pre>
  
  <p>The StoreName is coming through fine, but it appears that it is not assigning the parts as a sub-table to the store.  It is only returning 1 part per store in the sequence that they are stored in the parts table.  It does not appear to be using the StoreParts relationship at all.</p>
  
  <p>Any ideas?</p>