How to create a pivot table with dynamic column using linq tree expression?

I have been using this extension for pivoting list public static Dictionary> Pivot(this IEnumerable source, Func firstKeySelector, Func secondKeySelector, Func aggregate) { var retVal = new Dictionary>(); var l = source. ToLookup(firstKeySelector); foreach (var item in l) { var dict = new Dictionary(); retVal. Add(item.

Key, dict); var subdict = item. ToLookup(secondKeySelector); foreach (var subitem in subdict) { dict. Add(subitem.

Key, aggregate(subitem)); } } return retVal; } Hope this help.

I have been using this extension for pivoting list. Public static Dictionary> Pivot(this IEnumerable source, Func firstKeySelector, Func secondKeySelector, Func aggregate) { var retVal = new Dictionary>(); var l = source. ToLookup(firstKeySelector); foreach (var item in l) { var dict = new Dictionary(); retVal.

Add(item. Key, dict); var subdict = item. ToLookup(secondKeySelector); foreach (var subitem in subdict) { dict.

Add(subitem. Key, aggregate(subitem)); } } return retVal; } Hope this help.

Thanks for your reply, but it didn't work in my case. – user598956 Feb 8 at 4:45.

It is not possible to query a dynamic number of columns in sql. By extention it is not possible to do that with linq either as it is based on sql. So you are out of luck, sorry.

However you can request all existing pairs of {country, product} from sql server and do the remaining processing on the client (reconstruct countries and products by doing . Select(x => x. Product).Distinct() and so on, and then dynamically creating columns in a datagrid).

A pivot table with dynamic column is created (without quotes):. Create a pivot table with dynamic column.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions