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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:03:23+00:00 2026-05-10T14:03:23+00:00

Using LINQ to SQL, I have an Order class with a collection of OrderDetails.

  • 0

Using LINQ to SQL, I have an Order class with a collection of OrderDetails. The Order Details has a property called LineTotal which gets Qnty x ItemPrice.

I know how to do a new LINQ query of the database to find the order total, but as I already have the collection of OrderDetails from the DB, is there a simple method to return the sum of the LineTotal directly from the collection?

I’d like to add the order total as a property of my Order class. I imagine I could loop through the collection and calculate the sum with a for each Order.OrderDetail, but I’m guessing there is a better way.

  • 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. 2026-05-10T14:03:23+00:00Added an answer on May 10, 2026 at 2:03 pm

    You can do LINQ to Objects and the use LINQ to calculate the totals:

    decimal sumLineTotal = (from od in orderdetailscollection select od.LineTotal).Sum(); 

    You can also use lambda-expressions to do this, which is a bit ‘cleaner’.

    decimal sumLineTotal = orderdetailscollection.Sum(od => od.LineTotal); 

    You can then hook this up to your Order-class like this if you want:

    Public Partial Class Order {   ...   Public Decimal LineTotal {     get {       return orderdetailscollection.Sum(od => od.LineTotal);     }   } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started using Linq to SQL in a (bit DDD like) system which
I have been using LINQ to SQL for a while, and there is one
I'm using LINQ to SQL and C#. I have two LINQ classes: User and
I have a process in a website (Asp.net 3.5 using Linq-to-Sql for data access)
I have a table in the database that I'm retrieving using LINQ to SQL,
I have been having some issues with LINQ-To-SQL around memory usage. I'm using it
When using Linq to SQL and stored procedures, the class generated to describe the
I have a Linq to SQL class. There is a one to many relationship
I have the following code in a partial class and I'm using LINQ to
Let's say I have an Order table which has a FirstSalesPersonId field and a

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.