I have a question regarding LINQ to SQL. I would like to write the following query in LINQ:
SELECT DISTINCT([Column]),
COUNT([Column]) as [Count]
FROM [Table]
Can I do this in 1 query? Or do I have to initially select my distinct columns, and then for each select the count? That seems very clumsy and heavy (n-squared).
That query isn’t legal, as you’re using an aggregate (
COUNT) without grouping on the column that you’re selecting.What you want is something like this:
That’s easily expressed in LINQ to SQL.