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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:57:44+00:00 2026-06-19T02:57:44+00:00

I need to be able to either have an optional parameter in a Linq

  • 0

I need to be able to either have an optional parameter in a Linq query, or be able to assign the query to a var in something like an IF if that optional parameter needs to be removed from the query.

If I set the query var inside the IF statement then it tells me that the var doesn’t exist in context when I try to loop through it.

if (whichGroup == "All")
{
    var listOppLineData = (from o in db.opportunity_vws
                           where o.fiscal_yr_and_qtr == qtr
                           select o
                          );
}
else
{
    var listOppLineData = (from o in db.opportunity_vws
                           where o.fiscal_yr_and_qtr == qtr && o.Group == whichGroup
                           select o
                          );
}
            
foreach (var data in listOppLineData)  //listOppLineData doesn't exist here
{
 ...

I need to set the var before the IF statement I think, but I don’t know what to set it to.

var listOppLineData = ""; // gives me 
Cannot implicitly convert type 'System.Linq.IQueryable<Forecast.Models.opportunity_vw>' to 'string'

IQueryable listOppLineData = new IQueryable(); //gives me
        Cannot create an instance of the abstract class or interface 'System.Linq.IQueryable'
  • 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-19T02:57:45+00:00Added an answer on June 19, 2026 at 2:57 am

    Try this:

    IQueryable<opportunity_vw> listOppLineData;
    

    This is defining the variable, but you are waiting to initialise it.

    Also, looking at your query, you could do it all in one, like so:

    var listOppLineData = (from o in db.opportunity_vws
                          where o.fiscal_yr_and_qtr == qtr && (o.Group == whichGroup || whichGroup == "All")
                          select o
                          );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writting a VB.Net application. I need to be able to convert either
I need to be able to create an id for a hyperlink. I have
I need to be able to, using either V2 OR V3 (preferably 3), create
Either through bootstrapper or command line install, I need to be able to create
I need to be able to export PDF's that I am creating to JPEG,
I have a bunch of files that need to be parsed, and they all
I need to have a button style that will present 3 different texts of
Hi all i'm a bit stuck and need some help. I have a query
I need to be able to link for example Customers to either multiple Users
I have a problem where I need to be able to detect AJAX calls

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.