NickP
NickP

Reputation: 1414

Sum from LINQ query

Cannot get this to work. Want to get the sum of all the amounts int the database from the following LINQ statement:

        Dim currentPaid = From a In db.Payments
                          Where a.ForJob = id
                          Select a.Amount

        Dim totalPaid As Double = currentPaid.Sum()

As it underlines the second statment and says: Overload resolution failed because no accessible 'Sum' accepts this number of attributes.

Upvotes: 1

Views: 988

Answers (2)

divan
divan

Reputation: 29

Dim sum = (From a In db.Payments Where a.ForJob = id Select a.Amount).Sum();

Upvotes: 0

NickP
NickP

Reputation: 1414

Asked another question with code and someone answered my question exactly so the answer is below:

  Dim totalPaid = db.Payments.Where(Function(a) a.ForJob = jobId).Sum(Function(a) a.Amount)

Upvotes: 3

Related Questions