c# 按多列分组然后 select 计数 > 1 的所有字段

c# group by multiple columns then select all fields where count > 1

我有一个这样的 lambda 查询,

        List<string> ticketStatusOrder = new List<string>() { "Attended", "Issued", "Unpaid", "Cancelled" };

        var duplicate = dt.AsEnumerable()
            .OrderBy(x => ticketStatusOrder.IndexOf(x["TicketStatus"].ToString()))
            .GroupBy(x => new {EventID = x["EventID"].ToString(), ContactID = x["ContactID"].ToString()})
            .Select(x =>
            {
                var first = x.First();
                //return new {first.ItemArray};
                return new
                {
                    Type = first["type"],
                    Name = first["name"],
                    EventID = first["EventID"],
                    ContactID = first["ContactID"],
                    TicketStatus = first["TicketStatus"]
                };
            }).ToDataTable();

它没有按数字返回正确的顺序,有帮助吗?谢谢

通过

找到解决方案
  var duplicate = dt.AsEnumerable()
            .GroupBy(x => new {EventID = x["EventID"].ToString(), ContactID = x["ContactID"].ToString()})
            .Where(x => x.Count() == 1)
            .Select(x =>
            {
                var first = x.First();
                return new
                {
                    Type = first["type"],
                    Name = first["name"],
                    EventID = first["EventID"],
                    ContactID = first["ContactID"]
                };
            }).ToDataTable()

另一个问题,我们可以 return 新的 first.ItemArray 类似的东西到 return 中的任何东西吗?谢谢