【问题标题】:Three Hierarchical DataGrids with WCF RIA (EF) and Silverlight三个带有 WCF RIA (EF) 和 Silverlight 的分层数据网格
【发布时间】:2011-09-07 03:20:20
【问题描述】:

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

我的任务是创建一个具有三个分层网格的屏幕 - 主网格显示客户,第一个子网格显示订单,第三个显示 LineItems。 但是,这些网格并不包含在彼此之间。

所以这里的问题如下:

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

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

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

然而,这带来了一个问题,即每个客户(尤其是回头客)可以有很多订单,并且每个订单至少有 20 多个订单项。 (同样,这是针对分销业务的……订单量很大!)

那么有没有办法做到这一点而不必延迟加载所有订单和 LineItem 数据?另外,您将如何在每个网格上进行分页 - 每个网格最多显示 20 条记录?

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

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

【问题讨论】:

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


    【解决方案1】:

    嗯,解决这个问题很简单。

    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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多