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.
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).
This is really close...the trick would be to create the rejectList from dynamic statuses. It would be more like where I => i. Status in(list).
Can I do something like that? Basically another LINQ statement I guess? – farina Apr 12 at 19:23 Absolutely, to build the rejectList, you'd just have to devise a way to get a list of rejects you don't want.
For example: var rejectList = fullList. Where(i => rejectStatuses. Contains(i.
Status)); I'll update my original answer to reflect this change. – Thebigcheeze Apr 12 at 19:36.
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().
I have not tried this, so I am not guarantueeing anything, however foreach Bar f in filterBars { search(f) } Foo search(Bar b) { fooSelect = (from f in fooBunch where!(from be in f. BarList select b. BarId).
Contains(b. ID) select f).ToList(); return fooSelect; }.
From what I can tell, b. ID doesn't compile. The Contains method seems to loose context of b.
– farina Apr 12 at 19:29 You're using two variables named b, and the compiler probably finds it ambiguous. – Justin Morgan Apr 12 at 20:15.
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. So, long story short I want to use LINQ to filter out my list of objects based on objects from another list.
I hope this makes sense. I think I'm just lost on the Contains portion...I don't know how to write that.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.