Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 249289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:24:54+00:00 2026-05-11T21:24:54+00:00

This really should be easy, but I just can’t work it out myself, the

  • 0

This really should be easy, but I just can’t work it out myself, the interface is not intuitive enough… 🙁

Let’s say I have a State table, and I want to select all Counties from multiple States. In SQL that would be:

select c.*
  from State s join County c on c.StateCode = s.StateCode
 where s.TimeZone = -5 -- or some other criteria

The above example is trivial enough to convert to Linq in a static context:

var q = MyDataContext.GetTable<County>().Where(c => c.State.TimeZone = -5);

But where it starts getting complicated is if I want a more context sensitive query, such as the following:

public static List<County> GetCountiesForStates(List<State> states) {
  // gotta do something to return all the counties for all these states
}

Now I could do something like this inside that method:

var q = MyDataContext.GetTable<County>().Where(c => states.Contains(c.State));

but IMO that is really inelegant, because (a) I have to get a static MyDataContext instead of using the implicit data context of the State objects and (b) you’re working backwards, and if you start complicating the query further it gets even uglier.

Is there a way of starting the query with:

var q = states... // or "from s in states..."

Instinctively, I want to believe you can do this, but I haven’t yet found the way…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:24:54+00:00Added an answer on May 11, 2026 at 9:24 pm

    You can do this:

    var q = from c in countries
            from s in c.States
            where c.Property == Something
            select s;
    

    This will give you an enumeration of all states within all countries. This translates into the following:

    var q = countries.Where(x => c.Property == Something).SelectMany(c => c.States);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, this should be really easy, but I just don't have enough experience. I
This feels like it should be really easy, but I just can't get it
Ok really easy I know but not for me... I can not figure this
This seems like it should be really easy but I couln't find an answer
This really shouldn't be hard, I just can't figure out how to do it.
This seems like it should be really easy but I've been having trouble with
This should really be easy for an experienced android programmer. Unfortunately I don't know
This should really be allowed - I do not understand why it is not.
This should be really simple, but I have tried many solutions posted on the
This seems like it should be really simple, but I'm unable to figure this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.