New Posts New Posts RSS Feed: Master Detail
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Master Detail

 Post Reply Post Reply
Author
GeorgeB View Drop Down
Groupie
Groupie


Joined: 03-May-2010
Posts: 66
Post Options Post Options   Quote GeorgeB Quote  Post ReplyReply Direct Link To This Post Topic: Master Detail
    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


Edited by GeorgeB - 07-Sep-2010 at 2:29am
Back to Top
GeorgeB View Drop Down
Groupie
Groupie


Joined: 03-May-2010
Posts: 66
Post Options Post Options   Quote GeorgeB Quote  Post ReplyReply Direct Link To This Post Posted: 09-Sep-2010 at 11:42am

Hi

Anyone?
 
Is it possible to do without returning an anonymous type?
Back to Top
Molinari View Drop Down
Groupie
Groupie
Avatar

Joined: 25-Aug-2010
Posts: 42
Post Options Post Options   Quote Molinari Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
GeorgeB View Drop Down
Groupie
Groupie


Joined: 03-May-2010
Posts: 66
Post Options Post Options   Quote GeorgeB Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Molinari View Drop Down
Groupie
Groupie
Avatar

Joined: 25-Aug-2010
Posts: 42
Post Options Post Options   Quote Molinari Quote  Post ReplyReply Direct Link To This Post 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)
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
GeorgeB View Drop Down
Groupie
Groupie


Joined: 03-May-2010
Posts: 66
Post Options Post Options   Quote GeorgeB Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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) });
Back to Top
GeorgeB View Drop Down
Groupie
Groupie


Joined: 03-May-2010
Posts: 66
Post Options Post Options   Quote GeorgeB Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
GeorgeB View Drop Down
Groupie
Groupie


Joined: 03-May-2010
Posts: 66
Post Options Post Options   Quote GeorgeB Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down