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 开发者_如何学Cgrid, 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?
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.
精彩评论