在ria服务中将父数据和子数据绑定到DataGrid中以获取Silverlight 4 [英] Binding parent and child data into DataGrid in ria services for silverlight 4

查看:53
本文介绍了在ria服务中将父数据和子数据绑定到DataGrid中以获取Silverlight 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始学习Silverlight 4 RIA服务.我已经看过很多关于如何将数据绑定到网格的示例.但总是有一个被绑定的对象是一个没有子表的简单对象.

i've started learning Silverlight 4 RIA services. i've gone over alot of samples of how to bind data to a grid. but always there object being bound is a simple one with no child tables.

在我的数据库中,有一个用于员工的表和一个用于城市名称的表(id字段为pk).员工表中的CityId字段有一个FK.

in my DB there's a table for employees and a table for city names (with id field as pk). in the employee table theres a FK to the CityId field.

我尝试做的第一件事是显示员工列表和他们的城市名称.这是我按照所有教程中显示的常规方法完成的(创建edmx,创建域服务并使用数据源窗口创建数据网格)

the first thing i've tried to do was to show a list of employees and their city name. this i've done in the normal way shown in all the tutorials (create edmx, create domain service and using the datasource window to create the datagrid)

当我尝试绑定城市名称时,问题就开始出现了,在雇员(父实体)和citytypes(子实体)之间添加了FK

the problems started when i tried binding the name of the city throw the FK between employee (parent entity) and citytypes (child entity)

此行工作正常:

<代码>< sdk:DataGridTextColumn x:Name ="cityCodeColumn" Binding ="{Binding Path = CityCode}"Header ="CityCode" Width ="SizeToHeader"/>

此行不:

<代码>< sdk:DataGridTextColumn x:Name ="cityNameColumn" Binding ="{Binding Path = CityType.Name}" Header ="CityName" Width ="SizeToHeader"/>

在阅读更多内容后,我意识到域服务不仅会传递LINQ命令选择的实体的数据,而且不会传递子实体的信息.除非使用include属性.

after reading some more i've realized that the the domain service does not pass only the data of the entity selected by the LINQ command, and does not pass child entities info. unless using the include attribute.

所以我的问题是,是否有一种构建Silverlight应用程序的模式,而没有对所包含的实体之间的所有关联进行签名?

so my question is , is there a pattern of building a silverlight application with out signing all the associations between entities as included?

谢谢,奥伦

推荐答案

要在绑定员工记录时使城市信息可用,您需要确保在RIA域服务元数据中使用[Include]属性标记城市参考.

To have the City information available when binding your Employee record you need to ensure you are marking the City reference with an [Include] attribute in your RIA domain service metadata.

  [MetadataTypeAttribute(typeof(MyTestObject.MyTestObject_Metadata))]
  public partial class MyTestObject
  {

    internal sealed class MyTestObject_Metadata
    {
      // Metadata classes are not meant to be instantiated.
      private MyTestObject_Metadata()
      { }

      [Include]
      public AnotherObject Foo { get; set; }
    }
}

您还需要在查询中包含引用.

You also need to include the references in your query.

var results = this.ObjectContext.MyTestObject.Include(Foo);

希望这会有所帮助.

这篇关于在ria服务中将父数据和子数据绑定到DataGrid中以获取Silverlight 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆