Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am working on a complex function of multiple groupby using LINQ dynamically.
i have a query like :
C#
var groupByData = dataCollection.AsQueryable().GroupBy(strGroupby.ToString(),"it")
.select(strdata.ToString());

i want to access data through the collection that i have as "groupByData", but i am unable to do so.
When i found out in the quick watch all the values that i have found are the required correct values, going through quickwatch i found out something as...

system.linq.systemcore_enumerabledebugview<dynamicclass2>(groupByData).items[0]..... but it gives me an error when i tried this in my code.
How can i access the data i have in collection , it is of IQueryable return Type.

Thanks a lot in advance.

Nishant
Posted

1 solution

You seem to not understand delegates and lambda expressions.
A Linq expression based on the Enumerable extension methods as GroupBy etc. take delegates, usually in the form of lambda expressions.

E.g. the function Select is defined as described in Enumerable.Select(...)[^]. It takes a delegate that takes a source item and returns the result item.

E.g.
C#
static int Square(int i) { return i * i; }

static void Main(string[] args)
{
    var list = new List<int>() { 1, 2, 3 };
    Console.WriteLine(string.Join(", ", list.Select(Square))); // delegate as function reference
    Console.WriteLine(string.Join(", ", list.Select(i=>i*i))); // delegate as lambda expression
}


I don't know what your data are, but I guess you want to express something like:
C#
var groupByData = dataCollection.GroupBy(e=>e.it);

No ToString(). No clue why you want to convert to string...

Cheers
Andi
 
Share this answer
 
v6

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