Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linq sum

Status
Not open for further replies.

princesszea

Technical User
Aug 11, 2008
33
GB
Hi,

I need to get the sum of employees scores for each department using linq. I only need scores from departments that have more than 20 employees but not sure Where to put the Where clause also not sure if the query below is correct
Code:
       var departmentquery = from row in dt.AsEnumerable()
                        group row by row["department"] into grp

                                
                           select new
                           {
                               Sum = grp.Sum(r => r.Field<decimal>("score");

                           };
Many thanks
 
I have written the sql that brings back the correct data,is it possible for this query to be converted to linq

Code:
select d.departmentId,round(cast(sum(score)as decimal(10,2))/(SELECT sum(score) FROM table),2)
	From table t
--joins etc
	GROUP BY departmentId
 
why would you do this in linq? it makes more sense to do this on the database.

side note: you may want to consider using POCO (plain old compiled objects) rather than datasets/tables. they are more expressive about what is present/happening.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top