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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:09:46+00:00 2026-05-24T08:09:46+00:00

Okay so I have a listview control with 3 columns: Year | NetTotal |

  • 0

Okay so I have a listview control with 3 columns:

Year | NetTotal | GrossTotal

also i have a table called Orders with several columns, they contain information about the order and store the ID of the Customer they belong to.

Question is: how can i query that table with (preferably) linq (the datacontext is from LinqToSql) to return the following data?

I want to search for any entry with the matching CustomerID which took place, group them by Year, Sum the Totals respectively and add them to the listview?

I now i could use lamda expressions and aggregate, its just not clear how (option infer on,db is a datacontext object,CustomerID is an int32 variable):

Dim Orders = (From order In db.Orders Where order.CustomerID = CustomerID).GroupBy(Function(p) p.Date.Year).GetEnumerator

I reckon i’d have to create an anonymous type like the following:

Dim tmpYears = From prevs In db.Orders Select New With {.CustID = prevs.CustomerID, .Year = prevs.PaymentDate.Year, .NetPurchase, .GrossPurchase}

But how do I aggregate the Purchased column in a group?

Dim CustomerOrders = From ord In db.Orders Where Ord.CustomerID = custID Select ord
Dim tot = From O in CustomerOrders Select Aggregate netTot In O Into Sum(netTot.Price * netTot.Quantity * 1+ (netTot.Discount/100))

I want to merge the two.

Any suggestions? (I’ve read this but i want it in Linq because its a team project and we agreed on using Linq instead of sending .ExecuteQuerys and etc to the db.Also its a LinqToSQL solution so would be better if i could make some use of it)

  • 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-24T08:09:47+00:00Added an answer on May 24, 2026 at 8:09 am

    I can’t guarantee I understand your requirements exactly, but long story short it seems you want to display orders, grouped by year, with the aggregated sums for net/gross value, where the orders match a provided CustomerID?

    Sorry if the syntax is slightly out but I’m doing this freehand…

    Dim results = db.Orders.Where(Function(n) n.CustomerId = customerId).GroupBy(Function(n) n.Date.Year, Function(key, values) New With {.Year = key, .NetTotal = values.Sum(Function(n) n.NetPurchase * n.Quantity * (1 + (n.Discount/100))), .GrossTotal = values.Sum(Function(n) n.GrossPurchase)})
    

    This should provide you an anonymous type with Year, NetTotal, and GrossTotal populated as per the requirements I listed.

    EDIT: Also apologies for the one liner but I’m sure you can reformat it to taste.

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

Sidebar

Related Questions

Okay i have a custom server control that has some autocomplete settings, i have
Okay I have table: ID Name Description Picture 1 Alex Alex desc.. 2 2
Is it good or okay to have several frameworks in a project, or is
I have a custom control that is derived from ListView . This list view
Okay i have a HTML TABLE , with 4 TDs in a TR(tow) as
Okay I have a table that looks as following: id | status(bool) | devicename(text)
Okay I have this RewriteRule which is supposed to redirect any request for the
Okay I have a large CRUD app that uses tabs with Forms embedded in
Okay I have a series of objects based on a base class which are
okay i have found the way to run a video in a image.... the

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.