三个层次数据网格与WCF RIA(EF)和Silverlight

本文关键字:WCF Silverlight RIA EF 数据网 三个 层次 数据 网格 | 更新日期: 2023-09-27 17:58:10

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

我的任务是创建一个包含三个层次网格的屏幕——主网格显示客户,第一个子网格显示订单,第三个子网格显示LineItems。但是,栅格并不包含在彼此之中。

因此,这里的问题如下:

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

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

这会很好用的。在xaml中,第一个网格将绑定到服务上下文的Customers实体集,第二个绑定到第一个网格的选定项,第三个绑定到第三个网格的所选项。

然而,这带来了一个问题,即每个客户(尤其是回头客)都可能有许多订单,并且每个订单至少有20多个商品。(同样,这是一个分销业务…订单相当大!)

那么,有没有一种方法可以做到这一点,而不必LazyLoad所有订单和LineItem数据?此外,您将如何在每个网格上进行分页——每个网格最多显示20条记录?

我想在页面上加载抓取所有客户并绑定到客户网格。在选定的Item changed事件中,为客户获取所有订单。在为订单网格更改的选定项目上,获取订单的所有LineItems,并将LineItemsGrid绑定到LineItems。

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

三个层次数据网格与WCF RIA(EF)和Silverlight

这个问题的解决方案非常简单。

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.