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 20:07:36
 
 
To
25/06/2008 14:23:15
General information
Forum:
ASP.NET
Category:
LINQ
Miscellaneous
Thread ID:
01326680
Message ID:
01326800
Views:
13
Cool, looks like your coming along nicely on this.

>
>>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
Reply
Map
View

Click here to load this message in the networking platform