LINQ: Select where object does not contain items from list

后端 未结 4 1246
被撕碎了的回忆
被撕碎了的回忆 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:21

    dump this into a more specific collection of just the ids you don't want

    var notTheseBarIds = filterBars.Select(fb => fb.BarId);
    

    then try this:

    fooSelect = (from f in fooBunch
                 where !notTheseBarIds.Contains(f.BarId)
                 select f).ToList();
    

    or this:

    fooSelect = fooBunch.Where(f => !notTheseBarIds.Contains(f.BarId)).ToList();
    

提交回复
热议问题