简体   繁体   中英

grouping the list object with where clauses and return

I want to get the grouped list based on the where clause from the List. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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