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 279305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:01:16+00:00 2026-05-12T05:01:16+00:00

I currently have a list that contains the following CountryCode (string) CountryStr (string) RegionStr

  • 0

I currently have a list that contains the following

CountryCode (string)
CountryStr  (string)
RegionStr   (string)
RegionID    (int)
AreaStr     (string)
AreaID      (int)

This is a flattened set of linked data (so basically the results of a joined search that ive stored)

The MVC route will only pass one string which I then need to match up to the data at the right level in the heirachy.
So I’m trying to query the CountryStr then if it doesn’t produce results the region then the area; but I need to do that bit of the query and for instance…

 var datURL = (from xs in myList
               //query 1
               where xs.RegionStr == rarREF
               select new
               {
                regionID = xs.RegionId,
                CountryID = xs.CountryCd
               }
               //IF theres no results 
               where xs.AreaStr == rarREF
               select new
               {
                AreaID = xs.AreaID
                regionID = xs.RegionId,
                CountryID = xs.CountryCd
               }             
               ).ToList();

The only way I see of doing this at the moment is running each query separately then checking which returned values and using that one. I’m hoping there’s a cleverer, cleaner method.

  • 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-12T05:01:17+00:00Added an answer on May 12, 2026 at 5:01 am

    It won’t be very easy to read, but you could do this in a single pass using something like this:

    var datURL = (from xs in myList
                  where xs.RegionStr == rarREF || xs.AreaStr == rarREF
                  select new
                  {
                    AreaID = (xs.AreaStr == rarRef ? xs.AreaID : default(int)),
                    RegionID = xs.RegionId,
                    CountryID = xs.CountryId
                  }
                 ).ToList();
    

    It might also be easier to read the query if it’s rewritten slightly:

    var datURL = (from xs in myList
                  let isArea = xs.AreaStr == rarREF
                  let isRegion = xs.RegionStr == rarREF
                  where isRegion || isArea
                  select new
                  {
                    AreaID = (isArea ? (int?)xs.AreaID : null),
                    RegionID = xs.RegionId,
                    CountryID = xs.CountryId
                  }
                 ).ToList();
    

    If we save the comparison result, we can reuse it later. I also added a cast to int? to show how you could use a nullable value instead of using 0 as your “no Area” value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a page that contains an unordered list. That list is initially
We currently have an ant task that contains something similar to the following: <filelist
I currently have some code that pulls down a list of users in a
I currently have a view that contains a ListBox bound to a a collection
I have a List of Dictionaries that have keys of type string and values
I currently have a class that uses the KeyValuePair with List to store a
I have a list of strings (a List<String> ) that can have anywhere from
Question Updated I have a generic list which can contains the following values: Sector
I currently have a list view which has several rows of data and I
I receive a list of image URLs and currently I have several hidden img

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.