三个具有WCF RIA(EF)和Silverlight的分层DataGrids

时间:2011-06-02 14:30:23

标签: c# silverlight datagrid silverlight-4.0 wcf-ria-services

我想知道是否有更好的方法来编码以下场景。我有一个Customer实体,每个Customer实体都有许多订单。每个Order实体至少有一个或多个LineItem实体。

我的任务是创建一个具有三个分层网格的屏幕 - 主网格显示Customers,第一个子网格显示订单,第三个显示LineItems。 但是,网格不会彼此包含在内。

所以这里的问题如下:

如果我在Customer的Orders导航属性中使用[Include]属性,并且还使用Order的LineItems导航属性中的[Include]属性,那么我可以拥有以下WebService: / p>

public IQueryable<Customer> GetCustomersWithOrdersAndLineItems()
{
     return this.ObjectContext.Customers.Include("Orders.LineItems");
}

这样可以正常工作。在xaml中,第一个网格将绑定到服务上下文的Customers实体集,第二个网格将绑定到第一个网格的选定项目,第三个网格将绑定到第三个网格的选定项目。

然而,这会产生一个问题,即每个客户(特别是重复客户)可以拥有多个订单,每个订单至少包含20多个订单项。 (再次,这是一个分销业务......订单非常大!)

有没有办法在不需要LazyLoad所有订单和LineItem数据的情况下执行此操作?另外,如何在每个网格上进行分页 - 每个网格最多显示20条记录?

我在思考页面加载抓住所有客户并绑定到客户网格。在所选项目已更改事件上 - 获取客户的所有订单。在为订单网格更改的选定项目上 - 获取订单的所有LineItem并将LineItemsGrid绑定到LineItems。

这种方法的问题是,如果网格与项目源具有相同的服务上下文,您如何在网格中保持每个页面的状态?如何处理每个网格中当前页面的更改?

1 个答案:

答案 0 :(得分:0)

嗯,解决方法非常简单。

Create 3 Domain Service objects in XAML.
Service 1: Auto Load on start, 20 items at a time
Service 2: Do NOT Auto Load on start, 20 items at a time.
Service 3: Do Not Auto Load on start, 20 items at a time.

Grid 1: ItemSource = Service 1, 1 Way binding to Service1.Data property
Grid 2: ItemSource = Service 2, 1 Way binding to Service1.Data property
Grid 3: ItemSource = Service 3, 1 Way binding to Service1.Data property

Pager 1: ItemSource = Service 1
Pager 2: ItemSource = Service 2
Pager 3: ItemSource = Service 3 

Service 2: Add a QueryParameter. Set parameter to the SelectedItem.PrimaryKey of Grid1 via 1 way binding. Create a service method that accepts an int/guid (whatever the primary key is) and returns the matched records (server side). Set the query name DomainService in xaml to be the name of the service method with the word "Query" appended to it.

Service 3: Add a QueryParameter. Set parameter to the SelectedItem.PrimaryKey of Grid2 via 1 way binding. Create a service method that accepts an int/guid (whatever the primary key is) and returns the matched records (server side). Set the query name of the DomainService in xaml to be the name of the service method with the word "Query" appended to it.