Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq to sql, aggregate columns ,group by date into listview
    primarykey
    data
    text
    <p>Okay so I have a listview control with 3 columns:</p> <p>Year | NetTotal | GrossTotal</p> <p>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.</p> <p>Question is: how can i query that table with (preferably) linq (the datacontext is from LinqToSql) to return the following data?</p> <p>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?</p> <p>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):</p> <pre><code>Dim Orders = (From order In db.Orders Where order.CustomerID = CustomerID).GroupBy(Function(p) p.Date.Year).GetEnumerator </code></pre> <p>I reckon i'd have to create an anonymous type like the following:</p> <pre><code>Dim tmpYears = From prevs In db.Orders Select New With {.CustID = prevs.CustomerID, .Year = prevs.PaymentDate.Year, .NetPurchase, .GrossPurchase} </code></pre> <p>But how do I aggregate the Purchased column in a group?</p> <pre><code>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)) </code></pre> <p>I want to merge the two.</p> <p>Any suggestions? (I've read <a href="https://stackoverflow.com/questions/51092/sql-aggregate-function-and-group-by">this</a> 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)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload