Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
My query is like

C#
var query = dbContext.table1.join(dbcontext.table2,i=>i.table1.id,j=>j.table2.id,
     (i,j)=>new {
                   name = i.name,
                   hours = (new decimal?[]{ j.day1,j.day2,j.day3}.Sum()),
                   total = ???????
                 }).ToArray();


In my query In the hours field,I am getting the values of individual user working hours for three days. In the "total" field I want to display sum of all users "hours" values. can u tell me how to get the "total" value
Posted
Updated 15-Nov-12 20:55pm
v2
Comments
Herman<T>.Instance 16-Nov-12 3:51am    
hours.Sum() ?

what have you tried?
Rohit Shrivastava 16-Nov-12 18:08pm    
I hope you understand that "(new decimal?[]{ j.day1,j.day2,j.day3}.Sum())" will not be executed on sql server rather it would be executed on .Net side. Total of all users you can get from the result set e.g.

query.Sum(item=> item.hours)
Greysontyrus 19-Nov-12 5:57am    
That would be my answer You wouldn't want the total to appear for each anon type in the array anyway. It would be calculated each time if it were possible.
Rather than gathering the days into an array, just so you can use the linq Sum(), it would be better to simply add them (j.day1+j.day2+...+j.dayn) as that would be executed in the SQL.

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