Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL Group by Query to Linq

Author  Topic 

s2002
Starting Member

49 Posts

Posted - 2010-08-22 : 14:18:59
Hello
DB Table "name: PType" structure

ID Name Total CatID
1 My 10 1
2 Nu 20 2
3 My 11 1

I want to List PType records group by Name, order by Sum(Total)
I use below

select Name,sum(Total) as Total from PType
group by Name
order by SUM(Total) desc

Now I want to Convert above SQL query to linq But I Got Error . Is there any other way to have the same result and better linq query?

This is the Linq Query I Use

From PType In db.PType _
Group PType By PType .Name Into g = Group _
Order By _
g.Sum(Function(p) p.Total) Descending _
Select _
Name, _
Hits = CType(g.Sum(Function(p) p.Total),Int32?)
   

- Advertisement -