views:

133

answers:

1

I was looking at snippets and tutorials for quite some time now, but I can't find a complete answer - just some bits and pieces.

I have a database with 3 tables:

Product:

  • id uniqueidentifier
  • name nvarchar(50)

Category:

  • id uniqueidentifier
  • name nvarchar(50)

ProductCategory:

  • fk_product uniqueidentifier
  • fk_category uniqueidentifier

Obviously there is a many-to-many relationship involved - a product can have multiple categories and a category can be applied to multiple products.

The next step was to generate ADO.NET Model and the domain service from the database. This is pretty much simple and I think standard.

Now in the view I make use of DataGrid and DataForm provided by the Silverlight 4 Toolkit.

<toolkit:DataForm ItemsSource="{Binding Data, ElementName=ProductsSource}" Name="dataForm1" AutoCommit="True" />

and

<sdk:DataGrid x:Name="dataGird" ItemsSource="{Binding Data, ElementName=ProductsSource}" AutoGenerateColumns="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />

The data source ProductsSource is defined as such:

<riaControls:DomainDataSource Name="ProductsSource" QueryName="GetProductsQuery" AutoLoad="True">
        <riaControls:DomainDataSource.SortDescriptors>
            <riaControls:SortDescriptor Direction="Ascending" PropertyPath="title" />
        </riaControls:DomainDataSource.SortDescriptors>
        <riaControls:DomainDataSource.DomainContext>
            <domain:PortfolioDomainContext />
        </riaControls:DomainDataSource.DomainContext>
    </riaControls:DomainDataSource>

Now: What is the best way to present the data from this many-to-many relationship in the view? Is there a way to show a multiselect-enabled listbox inside the DataForm for a property which has an many-to-many relationship associated with it?

A: 

This is a possible duplication of this question

Apparently Many-to-many (where the EF model removes the association table) is not support in RIA services.

You need to include the association table. I think an association table is only included in an EF model if it contains any extra fields (additional to the 2 foreign keys), or of you break one of the associations and manage one side of the many-to-many relationship yourself.

Enough already