Silverlight RIA很多人都没有工作

时间:2010-11-13 17:29:27

标签: silverlight entity-framework many-to-many ria

我正试图在RIA / Silverlight中建立多对多的关系,但我似乎无法弄清楚如何。

我的数据库看起来像这样......

Stores     Parts      StoreParts
--------   -------    ----------
ID         ID         StoreID
StoreName  PartName   PartID

我在这个数据库上创建了一个实体数据模型。

我的XAML看起来像这样

<toolkit:Accordion Background="White" BorderThickness="1" Height="503" HorizontalAlignment="Left" Margin="207,32,0,0" Name="accordion2" SelectionMode="ZeroOrMore" VerticalAlignment="Top" Width="181">
    <toolkit:Accordion.ContentTemplate>
        <DataTemplate>
            <ListBox BorderThickness="0" ItemsSource="{Binding Parts}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding PartName}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </DataTemplate>
    </toolkit:Accordion.ContentTemplate>
    <toolkit:Accordion.Effect>
        <DropShadowEffect BlurRadius="8" />
    </toolkit:Accordion.Effect>
    <toolkit:Accordion.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding StoreName}" />
            </StackPanel>
        </DataTemplate>
    </toolkit:Accordion.ItemTemplate>
</toolkit:Accordion>

我的XAML代码背后:

StoreContext storeContext = new StoreContext();
accordion2.ItemsSource = storeContext.Stores;
storeContext.Load(storeContext.GetStoresQuery());

我的RIA DomainService:

[EnableClientAccess()]
public class StoreService : LinqToEntitiesDomainService<MenuTemp2Entities>
{
    public IQueryable<Store> GetStores()
    {
        return this.ObjectContext.Stores.Include("Parts");
    }
}

最后,我的RIA元数据

[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<Part> Parts { get; set; }

        public string StoreName { get; set; }
    }
}

StoreName正常运行,但似乎没有将零件作为子表分配给商店。每个商店只返回1份,它们存储在零件表中。它似乎根本没有使用StoreParts关系。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

看看这个可能有用的Codeplex项目。

http://m2m4ria.codeplex.com/