newbeee
newbeee

Reputation: 63

System.Linq.Dynamic library - need Count() example

I need most elegant solution for dynamic selecting/grouping/ordering via Linq2Entities (VB.NET/VS2012).

And I'm trying to use System.Linq.Dynamic library (http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx)

This construсtion works fine

Dim testQuery= testDB.testTable.Select("New(Field1)").GroupBy("New(Field1)", "it")

But this one (found this example somewhere on blogs/SO) generates error:

Dim testQuery= testDB.testTable.Select("New(Field1, Count())").GroupBy("New(Field1, Count())", "it")

The error is "No applicable method 'Count' exists in type 'testTable'"

I know that this library was born dead, but official MS solution for dynamic queries with expressions-trees is kinda scary. :-)

Upvotes: 0

Views: 609

Answers (1)

Josh Gallagher
Josh Gallagher

Reputation: 5329

If your aim is to retrieve the count of rows in testTable for each value of Field1, then I would have thought you want to firstly GroupBy Field1, then Select afterwards. So basically reverse the order of your Select and GroupBy and remove the Count() from the GroupBy.

Upvotes: 1

Related Questions