2011-06-02 53 views
0

我想知道是否有更好的方法来编码以下方案。我有一个客户实体,每个客户实体都有许多订单。每个Order实体至少有一个或多个LineItem实体。使用WCF RIA(EF)和Silverlight的三个分层数据网格

我的任务是创建一个三层网格的屏幕 - 主网格显示客户,第一个子网格显示订单,第三个显示LineItems。 但是,网格不包含在另一个中。

所以这里的问题是:

如果我使用在订单的[Include]属性客户的导航性能,同时也使用在了LineItem的[Include]属性订单的导航性能,比我能有以下WebService:

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

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

然而,这带来了每个客户(特别是重复客户)都可以有多个订单的问题,并且每个订单至少有20多个订单项。 (同样,这是一个分销业务...订单非常大!)

那么有没有办法做到这一点,而不必LazyLoad所有的订单和LineItem数据?另外你将如何去做与每个网格分页 - 每个网格最多显示20条记录?

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

这种方法的问题在于,如果网格与它们的项目源具有相同的服务上下文,那么您如何坚持网格内每个页面的状态?我应该怎样处理每个网格内当前页面的变化?

回答

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.