Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I was trying to group my data with the following query. But it does not group anything. What I am missing?

C#
var myList= (from t1 in liste
             group t1 by t1.ApprovalDate into x
             select new Invoice
             {
                CustomerID = x.FirstOrDefault().CustomerID,
                CustomerName = x.FirstOrDefault().CustomerName,
                CustomerSurname = x.FirstOrDefault().CustomerSurname,
                ApprovalDate  = x.FirstOrDefault().ApprovalDate,
                Total = x.Sum(t => t.Total)
              }
              ).ToList();
Posted
Comments
Naz_Firdouse 8-Apr-13 4:09am    
why are you using new Invoice...
you can use
select new
{
CustomerID = x.FirstOrDefault().CustomerID,
CustomerName = x.FirstOrDefault().CustomerName,
CustomerSurname = x.FirstOrDefault().CustomerSurname,
ApprovalDate = x.FirstOrDefault().ApprovalDate,
Total = x.Sum(t => t.Total)
}

Also are the values for ApprovalDate repeats in the list???

1 solution

ApprovalDate =l.ApprovalDate.Date


I solved DateTime with Time causes not to group by date. Splitting the time solved my problem. Thank you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900