透视可观察的集合
我在可观察集合中有这样的记录,
ID Department salary joingdate 1 .NET 5000 04/08/2011 2 .NET 6000 04/07/2011 3 JAVA 7000 04/08/2011 4 JAVA 8000 04/07/2011 5 .NET 9000 04/06/2011
现在我想要新的可观察集合,例如
Joingdate .NET(Salary) JAVA(Salary) 04/08/2011 5000 7000 04/07/2011 6000 8000 04/06/2011 9000 NULL
如何获得这种类型的可观察集合?
I have records like this in observable collection
ID Department salary joingdate 1 .NET 5000 04/08/2011 2 .NET 6000 04/07/2011 3 JAVA 7000 04/08/2011 4 JAVA 8000 04/07/2011 5 .NET 9000 04/06/2011
now I want new observable collection like
Joingdate .NET(Salary) JAVA(Salary) 04/08/2011 5000 7000 04/07/2011 6000 8000 04/06/2011 9000 NULL
How would I get this type of observable collection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您有与您的结构类似的以下结构:
并遵循可观察的集合:
您可以尝试此代码来解决您的问题,或者至少让您走上可能更好的解决方案:
我希望这可以帮助您找到解决方案! :)
Assuming you have follwing structure that resembles your structure:
And following observable collections:
You could try this code to solve your problem or at least get you on the way to a maybe better solution:
I hope this helps you getting to a solution! :)
不久前,我尝试了旋转和 ExpandoObject。这当然不是生产代码。
然后以某种方法在某个地方
Some time ago I played around with pivoting and the ExpandoObject. This is certainly not production code.
then in some method somewhere
由于数据的使用方式,我需要表格格式的结果,而不是嵌套对象格式。因此,下面的代码从数据列表中生成一个数据透视表。它的调用方式如下:
LINQ 扩展方法如下所示:
Due to how my data is consumed, I have needed the results in a table format, not a nested object format. So the code below produces a pivot from a list of data. It is called like this:
And the LINQ extension method looks like this: