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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:25:22+00:00 2026-05-21T03:25:22+00:00

I have this simple sql query: select c.LastName, Sum(b.Debit)- Sum(b.Credit) as OpenBalance from Balance

  • 0

I have this simple sql query:

select c.LastName, Sum(b.Debit)- Sum(b.Credit) as OpenBalance from Balance as b
inner join Job as j on (b.Job = j.ID)
inner join Client as c on (j.Client = c.ID)
Group By c.LastName

and I am trying to convert it to work in linq like this:

from b in Balance
join j in Job on b.Job equals j.ID
join c in Client on j.Client equals c.ID
group b by new { c.LastName } into g
select new { 
     Name = c.Lastname, 
     OpenBalance = g.Sum(t1 => t1.Credit) 
       }

but when I try to run it in LINQPad I get the following message:

The name ‘c’ does not exist in the
current context

and it highlights c.Lastname in select new statement.

Any help on this will be greatly appreciated.
Thank you.

  • 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-21T03:25:23+00:00Added an answer on May 21, 2026 at 3:25 am

    Well, you’ve grouped b by c.LastName. So after the grouping operation, you’re dealing with g which is a grouping with the element type being the type of b, and the key type being the type of c.LastName. It could well be that all you need is:

    select new { 
        Name = g.Key,
        OpenBalance = g.Sum(t1 => t1.Credit) 
    }
    

    … but if you need to get at any other aspects of c, you’ll need to change your grouping expression.

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

Sidebar

Related Questions

I have a simple sql query that goes like this: SELECT * FROM leaderboard
I have this very simple sql statement: SELECT max_dose FROM psychotropes WHERE (patient_meds.psychotrope =
i have this simple query : SELECT YEAR(P.DateCreated) ,MONTH(P.DateCreated) ,COUNT(*) AS cnt FROM tbl1,
I have a simple SQL query, SELECT * FROM phones WHERE manu='$manuf' AND price
I have a simple query select t.firstname, t.lastname, t.zipcode, t.city from name_data t where
I have this simple PHP code: $query = mysql_query(SELECT `title`, `url_title` FROM `fastsearch` WHERE
I have a simple SQL query that when run from C# takes over 30
Let's say I have the following simple query SELECT TOP 1 name FROM months
I have this rather simple SQL query, but it takes almost a minute to
i have a simple SQL query, but im struggling to replicate in LINQ select

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.