LINQ: Select where object does not contain items from list

后端 未结 4 1234
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 11:51

I\'m struggling with LINQ syntax here...thought I\'d toss it out here. I cant find exactly what I\'m looking for anywhere else.

OK, say I\'ve got this:



        
4条回答
  •  温柔的废话
    2020-12-02 12:17

    In general, you're looking for the "Except" extension.

    var rejectStatus = GenerateRejectStatuses();
    var fullList = GenerateFullList();
    var rejectList = fullList.Where(i => rejectStatus.Contains(i.Status));
    var filteredList = fullList.Except(rejectList);
    

    In this example, GenerateRegectStatuses() should be the list of statuses you wish to reject (or in more concrete terms based on your example, a List of IDs)

提交回复
热议问题