我有一个这样的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();
它没有按数字返回正确的顺序,有帮助吗?谢谢
答案 0 :(得分:0)
边做边找到解决方案
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()
另一个问题,我们可以返回新的first.ItemArray这样的东西来返回first中的内容吗?谢谢