简体   繁体   English

使用where子句将列表对象分组并返回

[英]grouping the list object with where clauses and return

I want to get the grouped list based on the where clause from the List. 我想基于列表中的where子句获取分组列表。 How I can do that. 我该怎么做。 Below is the example. 以下是示例。

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;
    }
}

Your example doesn't compile. 您的示例无法编译。 I assume you want to order the list by TrackId and filter on some order types. 我假设您TrackId排序列表, 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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM