LINQ: Need to query on the fields, not the ID's

Posted on 2012-08-15
Last Modified: 2012-08-16
_myList.OrderBy(s => s .MyId).ThenBy(s => s.ValueType).ThenBy(s => s.qId)

_myList is a generic list which contains foreign keys, but I'd like to alphabetize the list by the values of the strings pointed to, not the ID's.

MyId and qId are forieng keys.  What's the linq method to include this relationship and be sorting by the actual string's value?

Question by:newbieweb
    LVL 74

    Assisted Solution

    by:käµfm³d 👽
    It sounds like you need a join. what is the name of the foreign table and the name of the string column?

    Author Comment

    Just use:


    to demonstrate the syntax for the for MyId value, which is a primary key in MyTable.
    LVL 74

    Accepted Solution

    I believe this should do it.

    _myList.Join(_myTable1, o => o.MyId, i => i.MyId, (outer, inner) => new { myList = outer, MyIdString = inner.MyStringField })
           .Join(_myTable2, o => o.myList.qId, i => i.qId, (outer, inner) => new { myList = o, QIdString = inner.MyStringField });
           .OrderBy(s => s.myList.MyIdString)
           .ThenBy(s => s.ValueType)
           .ThenBy(s => s.QIdString);

    Open in new window


    Author Closing Comment


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
    A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now