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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:18:36+00:00 2026-05-16T20:18:36+00:00

I am trying to perform to calculation. I have a donations (d) table that

  • 0

I am trying to perform to calculation. I have a donations (d) table that contains Quantity Needed (d.QtyNeeded) and I need to determine the numbers of items still needed by pulling quantity filled (qtyfilled) from the donors table. Not every donation has a donor, so I need a conditional statement to handle nulls so the sum will work. When I try to compile, I am getting an error: *Operator ‘-‘ cannot be applied to operands of type ‘int’ and ‘bool’. I am not great at Linq yet, what am I missing or is there a better way?

QtyOpen = d.QtyNeeded - (from dv in db.Donors
                                    select dv).All(v => v.QtyFilled == null)
                                    ? 0
                                    : (from dv in db.Donations
                                       select dv.QtyFilled).Sum()
  • 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-16T20:18:37+00:00Added an answer on May 16, 2026 at 8:18 pm

    The problem is not the LINQ statement, but rather precedence in the subtraction operator. Consider this example:

    int result = quantity - true ? 0 : otherValue;
    

    This fails to compile for the exact same reason, Operator ‘-‘ cannot be applied to operands of type ‘int’ and ‘bool’. The solution is to simply group the conditional statement in parens:

    int result = quantity - (true ? 0 : otherValue);
    

    So, your example should compile by adding parens around your entire conditional operator statement.

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

Sidebar

Related Questions

If I had a label on a view that I wanted to have the
I want to create a model that doesn't map to a database table. Instead,
Im trying to retrieve a datatable that I put into a session variable, however
I have an application that is currently running on IIS 6.0 with one worker
I have two tables (with the same schema) Table1 id title D0 D1 D2
i have the below coding in winForms in 3 different btns. I have very
I'm trying to keep model logic within my model, but I can't get it
I am currently working on a homework assignment to generate what is known as
I asked a question a couple weeks ago about using setTimeout for a factorial
I'm looping to loop over a range with multiple rows and columns using Excel

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.