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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:07:13+00:00 2026-05-31T21:07:13+00:00

Here is my current, working, query: var lsFooterRow = from i in _context.Inventory where

  • 0

Here is my current, working, query:

var lsFooterRow = from i in _context.Inventory
                  where i.ClaimId == claimID
                  && i.Taxable == false
                  group i by new { i.ClaimId }
                      into grp
                      select new
                      {
                          SumOfReplValue = grp.Sum(i => i.Price),
                          SumOfACV = grp.Sum(i => i.ACV),
                          SumOfReplCost = grp.Sum(i => i.ReplacementCost)
                      };

What I’d like to add, to make it conditional, is something like this so that it adds a filter to the base query along with ClaimID and Taxable:

if (reportType == "R")
            lsFooterRow = lsFooterRow.Where(i => i.ReplCost > 0);

This is not working because is does not recognize ReplCost, only SumOfReplValue, SumOfACV and SumOfReplCost.

Can someone please tell me, without doing the query in two steps, a way to add this condition? If there is no way to do it, a two step approach would be greatly appreciated 🙂

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-05-31T21:07:14+00:00Added an answer on May 31, 2026 at 9:07 pm

    If I understand correctly, you should probably break out intial query into multiple pieces.

      var lsFooterRow = from i in _context.Inventory
                  where i.ClaimId == claimID
                  && i.Taxable == false
                  select i;
    
      // conditional where
      if (reportType == "R")
            lsFooterRow = lsFooterRow.Where(i => i.ReplacementCost > 0);
    
    
      var aggregateFooterRow =  from i in lsFooterRow
             group i by new { i.ClaimId }
                      into grp
                      select new
                      {
                          SumOfReplValue = grp.Sum(i => i.Price),
                          SumOfACV = grp.Sum(i => i.ACV),
                          SumOfReplCost = grp.Sum(i => i.ReplacementCost)
                      };
    

    That way you are filtering on the replacement cost before it gets aggregated, which sounds like what you want to do.

    You did express concerns about a two part query but that shouldn’t really pose a problem. The nice thing about this is it will not compose and execute the sql until you enumerate over the final version of the query. The entity framework engine is smart enough to simply add the second where as another condition in the final where statement in SQL. That means that your contitional where will neatly be part of the query rather than an afterthought. You can break up the query and add conditional things as much as you want.

    The ability to break up the query into multiple pieces and conditionally compose the query is a tremendous benefit that LINQ has over SQL.

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

Sidebar

Related Questions

Here's my current SQL statement: SEARCH_ALBUMS_SQL = SELECT * FROM albums WHERE title LIKE
Here is the updated question: the current query is doing something like: $sql1 =
Cited from http://xss-proxy.sourceforge.net/Advanced_XSS_Control.txt : As many here probably know, current XSS attacks typically come
Here is my current problem. I am working with the chat module and I'm
First off, here's my SQL query: SELECT research_cost, tech_name, (SELECT research_cost FROM technologies WHERE
I was working on my website and stuck there. My current code is here:
Here is my current question: I'm guessing that my problem (described below) is being
Here is my current setup: Database Role - MyDbRole Schema - MySchema User -
here is my current line of code: $(<li>).text($(this).text()).appendTo(#theList); Which results in <ul id=theList> <li>blah</li>
Here is the current code I am using: <UserControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml x:Class=ButtonPrototype.MainPage Width=640 Height=480>

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.