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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:07:01+00:00 2026-06-15T16:07:01+00:00

I decided to try my hand at LINQ and so far its been a

  • 0

I decided to try my hand at LINQ and so far its been a miserable failure. I need to convert the following SQL query to LINQ:

SELECT 
MAX(A.NEXTPAYMENTDATE) as NextPaymentDate
, SUM(B.PurchasePrice) - SUM(A.Amount) AS BALANCE
, c.FirstName
, c.LastName
, b.[year]
, b.make
, b.model
FROM Payments A
JOIN Vehicles B ON A.VehicleId = B.Id
JOIN Customers C ON  b.CustomerId = c.Id
GROUP BY VehicleId, c.FirstName, c.LastName, b.[year], b.make, b.model
HAVING SUM(B.PurchasePrice) - SUM(A.Amount) > 0

This is what I have so far. It seems to work to a certain extent, but I don’t know how to progress from here.

var groupedpayments = 
    from payments in db.Payments
    group payments by new { payments.VehicleId }
    into paymentGroup
        let maxDate = paymentGroup.Max(x => x.NextPaymentDate)
        let paid = paymentGroup.Sum(x => x.Amount)
    select 
    new { Payments = paymentGroup.Where(x => x.NextPaymentDate == maxDate)};
  • 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-15T16:07:02+00:00Added an answer on June 15, 2026 at 4:07 pm

    I think that is what you need.

    var query =
        Payments.Join(Vehicles, p => p.VehicleId, v => v.Id, (p, v) => new {p, v})
            .Join(Customers, d => d.v.CustomerId, c => c.Id, (d, c) => new {d, c})
            .GroupBy(r => 
                       new {
                               r.d.p.VehicleId,
                               r.d.v.year,
                               r.d.v.make,
                               r.d.v.model,
                               r.c.FirstName,
                               r.c.LastName
                           },
                     (g, data) =>
                       new {
                               FirstName = g.FirstName,
                               LastName = g.LastName,
                               Year = g.year,
                               Make = g.make,
                               Model = g.model,
                               NextPaymentDate = data.Max(dd => dd.d.p.NEXTPAYMENTDATE),
                               Balance = data.Sum(dd => dd.d.v.PurchasePrice)
                                          - data.Sum(dd => dd.d.p.Amount)})
             .Where(r => r.Balance > 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was bored and decided to try my hand at using Linq to solve
I decided to try to my hand at this, and have had a somewhat
As I posted earlier here I've decided to try my hand at one of
I'm an experienced iOS dev and I have decided to try my hand at
Decided to try and learn Perl, and currently need to process a number of
I decided to try my hand in jQuery $('#tabs').tabs(); and make my tabs vertical.
I decided to try out LINQ for the first time to try and solve
I decided to try http://www.screwturn.eu/ wiki as a code snippet storage utility. So far
Having decided to try AForge for video and imaging stuff, I tried to implement
i am new to scrapy and decided to try it out because of good

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.