2011-12-23 79 views
4

我有列表List<Employee>它包含了像Linq查詢與列表<T>

Name Year Salary 

John 2001 10000 
Warn 2001 11000 
George 2001 12000 
Nick 2001 13000 
Warn 2002 14000 
John 2002 15000 
Adam 2002 16000 
Kile 2003 17000 
John 2003 18000 
Kile 2004 19000 
Warn 2004 20000 

我需要這樣的

Year John Warn George Nick Adam Kile 
---------------------------------------------------------- 
    2001 10000 11000 12000 13000 0  0 
    2002 15000 14000 0  0  16000 0 
    2003 18000 0  0  0  0  17000 
    2004 0  20000 0  0  0  19000 

轉換是否有可能與LINQ數據?

+1

[使用LINQ透視數據]的可能重複(http://stackoverflow.com/questions/963491/pivot-data-using-linq) – Oded 2011-12-23 17:10:43

+0

你真的想作爲導致的事情的清單屬性如「小數約翰」?你有準備好的類型嗎? – 2011-12-23 17:13:47

回答

2
var annualGroups = 
     from e in List<Employee> 
     group e by e.Year into y 
     select new { Year = y.Key, Employees = y };