我想按类上的WorkGroup.GroupId属性进行分组 public class Employee{ public int EmployeeID {get; set;} public Group WorkGroup {get; set;}} 但是我需要输出组名属性(可能有重复但在同一个groupid之间相同) 喜欢的东
public class Employee { public int EmployeeID {get; set;} public Group WorkGroup {get; set;} }
但是我需要输出组名属性(可能有重复但在同一个groupid之间相同)
喜欢的东西(这当然不起作用):
var grps = from emp in Emps group emp by emp.WorkGroup.GroupID into g select new { GroupID = g.Key, Title = g.Key.WorkGroup.GroupTitle, Employees = g };
我正在寻找允许我这样做的输出:
foreach (var g in grps) { Console.WriteLine(g.Title + "-" + g.GroupID); foreach (var e in g.Employees) { Console.WriteLine(e.EmployeeID); } }只按ID和标题分组:
var grps = from emp in Emps group emp by new { GroupID = emp.WorkGroup.GroupID, GroupTitle = emp.WorkGroup.GroupTitle } into g select new { GroupID = g.Key.GroupID, GroupTitle = g.Key.GroupTitle, Employees = g };