linq兩種寫法,以下所示:spa
1.code
var resultInformation = from outer in userInformation from inner in outer.Value let data = new { Outer = outer.Key, Inner = inner.Key, Value = inner.Value } orderby data.Outer, data.Inner, data.Value select data;
2.orm
var resultInformation = from student in userInformation orderby student.Key select new { studentId = student.Key, courses = from courseScore in student.Value orderby courseScore.Value descending select new { course = courseScore.Key, score = courseScore.Value } };
等價寫法:blog
var resultInformation = userInformation .SelectMany(i => i.Value, (key, inner) => new { Outer = key, Inner = inner.Key, Value = inner.Value}) .OrderBy(e => e.Outer) .ThenBy(e => e.Inner) .ThenBy(e => e.Value);