얼마 전 나는 피벗과 ExpandoObject를 가지고 놀았습니다. 확실히 생산 코드가 아닙니다.
public static dynamic pivot(IEnumerable<Employee> rows)
{
IDictionary<string, Object> expando = new ExpandoObject();
expando["Joindate"] = rows.First().Joindate;
foreach (var row in rows)
{
expando[row.Department] = row.Salary;
}
return (dynamic)expando;
}
다음 어딘가에
var employees = new ObservableCollection<Employee>() {
new Employee() {ID=1, Department="NET", Salary=5000, Joindate=new DateTime(2011,04,08)},
new Employee() {ID=2, Department="NET", Salary=6000, Joindate=new DateTime(2011,04,07)},
new Employee() {ID=3, Department="JAVA", Salary=7000, Joindate=new DateTime(2011,04,08)},
new Employee() {ID=4, Department="JAVA", Salary=8000, Joindate=new DateTime(2011,04,07)},
new Employee() {ID=5, Department="NET", Salary=9000, Joindate=new DateTime(2011,04,06)}
};
var distinctDates = employees.Select(j => j.Joindate).Distinct().OrderByDescending(d => d);
var salaryByDepartmentAndJoindate = distinctDates.Select(d => pivot(employees.Where(jd => jd.Joindate == d)));
var result = new ObservableCollection<dynamic>(salaryByDepartmentAndJoindate);
앞에'6 .NET 9500 04/08/2011'이 있다면 그 결과는 무엇을 할 것인가? –
데이터를 피벗하려고하는 것 같습니다. –