How to drill deeper into linked tables with linq?

Thread is closed for posting
2 posts, 0 answers
  1. kieron
    kieron avatar
    9 posts
    Member since:
    Dec 2010

    Posted 03 Nov 2011 Link to this post

    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 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 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
  2. Thomas
    Thomas avatar
    590 posts

    Posted 03 Nov 2011 Link to this post

    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.

    the Telerik team

    NEW and UPDATED OpenAccess ORM Resources. Check them out!

Back to Top