Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq Remove results with ALL statement
    primarykey
    data
    text
    <p>Hi I'm trying to use Linq to remove "all" entities from a list.</p> <p>Problem: I'm searching for users that have certain certificates in my database. Thing is that it returns them row by row.... But what I need to check is: If the user holds all the required certificates. This should be checked against my int array. </p> <p>This is my array: [3,5,16], now I want to delete all user who does not have all three of those from the list. Name of the array in code is <strong>mandatory</strong>!</p> <p>The listitems I get back looks like this</p> <p>listitem.CertificateValue <br> listitem.Uid<br> listitem.NameOfPerson</p> <p>So basicly for this example Peter has <strong>three rows</strong> in the list, in this case all the rows needed to stay in the list. But Philip only has 2 rows and hence both of these should be deleted since he does not fullfill the total search criteria.</p> <p>Also copyOfMandatoryis just to not mess with the original collection and cause an expection(collection size changed).</p> <pre><code>foreach (var item in copyOfMandatory) { if (!mandatoryusers.All(i =&gt; mandatory.Contains(i.CertificateValue) || i.Uid == item.Uid)) { mandatoryusers.RemoveAll(i =&gt; i.Uid == item.Uid); } } </code></pre> <p><strong>UPDATE</strong> RemoveAll works like a charm it the if statement that does not work as expected.</p> <p>Doing this it does not take away any part of the list, I began wiht &amp;&amp; instead of || but whne doing that it kills everything but the last person it encounters as long as he/she fullfills the search criteria.</p> <p>Anyone have a hint on how to do this? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload