This is a migrated thread and some comments may be shown as answers.

How to drill deeper into linked tables with linq?

1 Answer 67 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
kieron
Top achievements
Rank 1
kieron asked on 03 Nov 2011, 02:44 PM
I am staring to pickup using telerik ORM with querying linq quite easily however I am a bit stumped. I have a class called Project. This has Many to Many Association to class Company using join table, WHich has a one to many association to contacts.

I am able to get a list of all the companys related to a project by following the project.company.tolist style, however how can i get a list of the Contacts related to that project based on the company associated to the projecT? basically i need project.company.contacts.tolist() or equivalent somehow.

 im having trouble going that one depth further. I cant find any info on how to do that. or im not sure what i should be searching for. any help appreciated

1 Answer, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 03 Nov 2011, 04:59 PM
Hello Kieron,

assuming the model that you've described to me, I would propose to use something like

var q = from p in sc.Extent<ModelOld.XProject>()
             where p.Start == DateTime.Now
             from c in p.Companies
             from t in c.ZContacts
             select t.FirstName;

The LINQ expression given above generates then SQL similiar to

SELECT d.[first_name] AS COL1                  FROM [x_project] a JOIN [y_compan
y_x_project] AS b ON (a.[id] = b.[id2]) JOIN [y_company] AS c ON (b.[id] = c.[id
]) JOIN [z_contact] AS d ON (c.[id] = d.[id2]) WHERE a.[strt] = ?

So a list of all FirstNames of all Contacts of all Companies associated with the project started at the given DateTime.Now is returned.

Regards,
Thomas
the Telerik team

NEW and UPDATED OpenAccess ORM Resources. Check them out!

Tags
LINQ (LINQ specific questions)
Asked by
kieron
Top achievements
Rank 1
Answers by
Thomas
Telerik team
Share this question
or