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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:51:17+00:00 2026-06-05T22:51:17+00:00

I am trying to include an IF within my LET in LINQ but i

  • 0

I am trying to include an IF within my LET in LINQ but i can’t get it to work, it seems to work for the ternary operator, but this is TRUE or FALSE and i need to have more than 2 options.

I think this explains it well

Basically i have a select which selects items using joins from a DB. Then the i get the status for each record but i have to make a join on separate tables depending on the type from products.type

var tst = from p in products join i in info on p.id equals i.pid

// if p.type = "home" then ...

let status = from s in homestatus
select new { status = s.status }

// if p.type ="offshore" then


let status = from s in offshorestatus
select new { status = s.status }


// if p.type ="internal" then


let status = from s in internalestatus
select new { status = s.status }

select new {
name = p.name,
status = status.StatusText
}

Anybody have any ideas how to do a standard IF so i can select which STATUS (let) i wish to execute.

Thanks in advance

  • 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-06-05T22:51:18+00:00Added an answer on June 5, 2026 at 10:51 pm

    You can do that with the conditional operator (1)

    var tst = from p in products join i in info on p.id equals i.pid
    
    let status = p.type = "home" ? homestatus.Select(s=>s.status) :
                 p.type = "offshore" ? offshorestatus.Select(s=>s.status) :
                 p.type = "internal" ? internalestatus.Select(s=>s.status) : null
    select new {
    name = p.name,
    status = status != null ? status.StatusText : string.Empty;
    }
    

    If you are not using the status for anything else than the StatusText you could also do it like this

    var tst = from p in products join i in info on p.id equals i.pid
    
    let status = (p.type = "home" ? homestatus.Select(s=>s.status.StatusText) :
                 p.type = "offshore" ? offshorestatus.Select(s=>s.status.StatusText) :
                 p.type = "internal" ? internalestatus.Select(s=>s.status.StatusText) : null) ?? string.Empty
    select new {
    name = p.name,
    status = status;
    }
    

    (1) A ternary operator is any operator that takes three arguments, of which there at present is only one in C# called the conditional operator

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

Sidebar

Related Questions

I'm trying to get all dependencies (include transitives) within my plugin using mavenProject.getArtifacts() but
I'm trying to include a link within <td></td> , but it's not showing at
I am trying to include a binary file within a zip file and below
I'm trying include this barcode source code Stefanhafeneger - Barcode github.com to my project
I'm trying to include a hyperlink in my email but it is just showing
I am trying to include <% @using System.Web.Script.Serialization%> but it is giving me error
Hi I am trying to include a perl script within my shtml file. Unfortunately
I am trying to include a ListView within an Activity that is running inside
I'm trying to include specific 'admin view' files from within a folder structure. I'm
I'm trying to include a PHP file called includes.php which is not contained within

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.