In my controller I am returning a db query result (list of objects) defined by my model. I'm displaying this in the view. For example:
| prop1 | prop2 | prop3 | prop4 | prop5 |
| ------------ | ------------ | ------------ | ------------ | ------------ |
| AAA | 1123 | 400 | 35% | $600 |
| BBB | 3444 | 23 | 45% | $235 |
| CCC | 5000 | 55 | 15% | $555 |
| DDD | 2500 | 264 | 70% | $243 |
I would like to pivot this result to look like below:
| prop1 | AAA | BBB | CCC | DDD |
| ------------ | ------------ | ------------ | ------------ | ------------ |
| prop2 | 1123 | 3444 | 5000 | 2500 |
| prop3 | 400 | 23 | 55 | 264 |
| prop4 | 35% | 45% | 15% | 70% |
| prop5 | $600 | $235 | $555 | $243 |
What's the best way to achieve this? I had initially pivoted in the SQL query and had a model representing the bottom result , however it became difficult to manage as I had frequent changes and requests to add new fields calculated from other columns etc.
1条答案
按热度按时间atmip9wb1#
请参见下面的示例实现扩展方法,该方法使用反射来透视
IEnumerable<T>
。