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

  • Home
  • SEARCH
  • 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 730943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:58:10+00:00 2026-05-14T06:58:10+00:00

I am trying to get the below linq query to return -1 if there

  • 0

I am trying to get the below linq query to return -1 if there isn’t any current value. I was looking at this article on MSDN, here, and it seemed that DefaultIfEmpty() was what I wanted.

Unfortunately, I am getting a The type arguments cannot be inferred from the usage. Try specifying the type arguments explicitly. error.

I guess I am not sure what that means or what it is telling me to do. Can someone explain, please.

 public static int CheckForDRIID(int personID)
    {
        using (var context = ConnectDataContext.Create())
        {
            var masterIndex =
                (from applicationAssociation in context.tblApplicationAssociations
                 where applicationAssociation.ApplicationID == 1 && applicationAssociation.PersonID == personID
                 select applicationAssociation.PersonApplicationID).DefaultIfEmpty(-1).Single();


            return Convert.ToInt32(masterIndex);
        }
    }
  • 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-14T06:58:11+00:00Added an answer on May 14, 2026 at 6:58 am

    -1 is an int and applicationAssociation.PersionApplicationID isn’t, so it doesn’t know what to return. You could replace -1 with the same type as applicationAssociation.PersionApplicationID, “-1”. Or specify the type like DefaultIfEmpty<string>. And a third options is to do the Convert.ToInt32 in the select.

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

Sidebar

Related Questions

I am trying to get key-value-observing to work for an NSMutableArray. Below is the
Can't seem to figure this out, see code below. Trying to make a GET
I've been trying to get the Count for my Value field in my query
I'm trying to get a paged query to work properly using LINQ and NHibernate.
I'm trying to update a record with LINQ, but get this error: Property or
I'm trying to build an expression tree for this linq query: so I can
Am trying to get linq to call a stored procedure. I know this is
I am trying to get decimal value using LINQ in a MVC3 project. How
I'm having some problems trying to get the code below to output the data
I'm trying to get from Line #1 to Line #2 in the below code:

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.