我想根据List中的where子句获取分组列表。我怎么能这样做以下是示例。
public class OrderUpdate
{
public string Value { get; set; }
public int OrderType { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public long OrderId { get; set; }
public string TrackingId { get; set; }
public OrderUpdate GetGroupedList()
{
var UpdateList = new List<OrderUpdate>();
var groupedList = UpdateList.GroupBy(u => u.TrackingId);
// where OrderType in (1, 2, 3, 4) and add this in groupedlist
// which is objecct of OrderUpdate
return groupedList;
}
}
答案 0 :(得分:1)
你的例子没有编译。我假设您要按TrackId
订购列表并过滤某些订单类型。
public IEnumerable<OrderUpdate> GetList()
{
var validOrderTypes = new[] {1, 2, 3, 4};
var UpdateList = new List<OrderUpdate>();
// TODO: fill the list
return UpdateList
.Where(u => validOrderTypes.Contains(u.OrderType))
.OrderBy(u => u.TrackId);
}