Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2012-08-15
4
Medium Priority
?
629 Views
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?

Thanks!
0
Comment
Question by:newbieweb
  • 2
  • 2
4 Comments
 
LVL 75

Assisted Solution

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

Author Comment

by:newbieweb
ID: 38298068
Just use:

MyTable
MyStringField

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

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 38300379
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

0
 

Author Closing Comment

by:newbieweb
ID: 38301528
Thanks!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

572 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