使用 WCF RIA (EF) 和 Silverlight 的三个分层 DataGrid

发布于 2024-11-11 18:03:48 字数 966 浏览 2 评论 0原文

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

我的任务是创建一个具有三个分层网格的屏幕 - 主网格显示客户,第一个子网格显示订单,第三个子网格显示 LineItems。 然而,网格并不相互包含。

因此,这里的问题如下:

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

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

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

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

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

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

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

I was wondering if there is a better way of coding the following scenario. I have a Customer entity, and each Customer entity has many Orders. Each Order entity has at least 1 or many LineItem entities.

My task is to create a screen with three hierarchical grids - the main grid displays Customers, the first child grid displays orders, and the third displays LineItems.
However, the grids are not contained within one another.

So the issue here is the following:

If I use the [Include] attribute in the Orders navigational property of the Customer, and also use the [Include] attribute in the LineItems navigational property of the Order, than I can have the following WebService:

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

This will work fine. In the xaml the first grid will be bound to the Customers entity set of the service context, the second - to the selected item of the first grid, and the third - to the selected item of the third grid.

This however poses the issue that each customer (repeat customers especially) can have many orders, and each order has at the very least 20+ line items. (Again, this is for a distributing business... the orders are quite large!)

So is there a way to do this without having to LazyLoad all the order and LineItem data? Also how would you go about doing this with paging on each grid - display maximum of 20 records per grid?

I was thinking on the page load grab all customers and bind to the the customers grid. On the selected Item changed event - grab all orders for the customer. On the selected item changed for the orders grid - grab all LineItems for the order and bind the LineItemsGrid to the LineItems.

The issue with this approach is how do you persist the state of each page within the grid if the grids have the same service context as their items source? What should I do to handle the changing of the current page inside each grid?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你对谁都笑 2024-11-18 18:03:48

嗯,解决这个问题的方法非常简单。

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.

Well, the solution to this is pretty simple.

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文