Print Page | Close Window

Master Detail

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2129
Printed Date: 10-Jun-2026 at 8:33pm


Topic: Master Detail
Posted By: GeorgeB
Subject: Master Detail
Date Posted: 05-Sep-2010 at 10:23am
Hi
 
I'm using DevForce Silverlight 6.0.5.
 
I'm probably missing something really simple but I want to be able to return all customers and only their open sales orders.
 
Since a customer could have a 1000 orders and only 5 open orders, I don't want to have all the orders coming through. Obviously some customers will have no open orders, but I want those customers to come through. When I put the where clause with open orders, I only get the customers with open orders.                     
 
I didn't find anything in the forums which gave me a specific answer but I did try a few things but without any luck.
 
Kr
George



Replies:
Posted By: GeorgeB
Date Posted: 09-Sep-2010 at 11:42am

Hi

Anyone?
 
Is it possible to do without returning an anonymous type?


Posted By: Molinari
Date Posted: 09-Sep-2010 at 12:22pm
hey George

you did not put an column ID in ORDER.

adds an ID column in ORDER and test.



Posted By: GeorgeB
Date Posted: 10-Sep-2010 at 11:24am
Hi
 
You lost me. There is no issue with my tables and their relationships.
 
Here is something similar to what I'm trying:-
 
var customerQuery = from c in _mgr.EntityManager.Customers
                                    .Where(c => c.Country == "UK")
                                    .Include("Orders")
                                  select c;
 
var opCustomers = customerQuery.ExecuteAsync();
opCustomers.Completed += OpCustomersCompleted;
 
This gives all the Orders for every customer in the UK. I want every customer but for their orders, I only want open orders.
 
So something like this (but obviously this doesn't work) :-
 
var customerQuery = from c in _mgr.EntityManager.Customers
                                    .Where(c => c.Country == "UK")
                                    .Include("Orders").Where(o => o.IsOpen)
                                  select c;
 
kr
George


Posted By: Molinari
Date Posted: 10-Sep-2010 at 12:05pm
Hi
Can You show image of your EDMX Model.

There is problem to show include orders on datagrid.Datagrid shows only record which have
its difficult for him to show inside from group.

For your solution you can use View or make class and do manually
or try to show records with join (using Lamda)


Posted By: DenisK
Date Posted: 10-Sep-2010 at 12:07pm
Hi George;

Could you clarify what you're trying to do? You want to query customers that satisfy the following conditions:

1. All customers in UK

&&

2. Only customers that have open orders

Correct?


Posted By: GeorgeB
Date Posted: 10-Sep-2010 at 12:18pm
Hi Denis
 
Yes all UK customers and I want all customers even those with no orders. So if I have 100 customers in the UK I want all 100.
 
And then for the orders, I only want to include the open orders.
 
After a few months I will have a few thousand orders per customer. I don't want the completed orders as this means I will be pulling down a huge amount of unnecessary data.
 
Kr
George


Posted By: DenisK
Date Posted: 10-Sep-2010 at 2:47pm
George;

You have do it with anonymous type. The Include syntax can't be restricted with a Where clause. Your query should look something like this:

var customersWithFilteredSalesOrder = _mgr.Customers
        .Where(c => c.Country == "UK")
        .Select(c => new { customers = c, orders = c.Orders.Where(o => o.IsOpen) });


Posted By: GeorgeB
Date Posted: 11-Sep-2010 at 5:02am
Hi Denis
 
Okay I have it working with anonymous types (which wasn't my goal) but it's working.
 
This is a limitation with EF I assume? I see there is a request with the EF team to have the Include filter results. Not too many votes - 34 so far.
 
Thanks for the assistance.
 
Kr
George


Posted By: GeorgeB
Date Posted: 13-Sep-2010 at 11:55am
Hi
 
One more issue with this.
 
var customersWithFilteredSalesOrder = _mgr.Customers
        .Where(c => c.Country == "UK")
        .Include(s => s.SalesOffice)
        .Select(c => new { customer = c, c.SalesOffice, orders = c.Orders.Where(o => o.IsOpen) });
 
I have an Include which brings through the sales office but when I get the results and load them into my ObservableCollection, they're not there.
customersWithFilteredSalesOrder .ExecuteAsync((op) =>
                                          {
                                              Customers new ObservableCollection<Customer>();
                                              foreach (var anonCustomer in op.Results)
                                              {
                                                  Customer customer anonCustomer.Customer;
                                                  customer.SalesOfficeanonCustomer.Customer.SalesOffice;
                                                                                    
                                                  foreach (var anonOrder in anonCustomer.Orders)
                                                  {
                                                      customer.Orders.Add(anonOrder);
                                                  }
                                     
                                                  Customers.Add(customer);
                                              }
                                          });
Just a note - this is not my actual code so I hope I've transcribed it correctly.
 
Kr
George



Print Page | Close Window