Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cool: Using FK relations (Associations) instead of Joins
Message
From
25/06/2008 14:23:15
 
 
To
25/06/2008 13:57:25
General information
Forum:
ASP.NET
Category:
LINQ
Miscellaneous
Thread ID:
01326680
Message ID:
01326715
Views:
13
>Nope it's bidirectional you get a link to the parent in the child and an EntitySet<T> collection of children in the parent.
Ahh, this comment helped me see how to get the typed object collection I've been chasing with you for a few days.

At first I was getting anonymous type with this method:
            var CustomerList = (from p in db.job_info
                                join c in db.customers on p.cust_num equals c.custno
                                where p.status == 'A'
                                orderby c.company
                                select new { custno = c.custno, c.company, c.phone, c.faxno }
                                ).Distinct();
Then, I saw an example that used a subquery technique to get a typed collection of Customer objects:
            var subq = (from p in db.job_info
                        where p.status == 'A'
                        orderby p.customer_source.company
                        select p.customer_source.custno).Distinct();

            IQueryable<customer_source> CustomerList = from a in db.customers
                                                       where subq.Contains(a.custno)
                                                       select a;
NOW, I can do it all in one query by using the "link to the parent" property of the child:
            IQueryable<customer_source> CustomerList = (from p in db.job_info
                                                            where p.status == 'A'
                                                            orderby p.customer_source.company
                                                            select p.customer_source       <---- the magic occurs here
                                                            ).Distinct();
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform