Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ Combine Queries
    text
    copied!<p>I have two collections of objects of different type. Lets call them type <strong>ALPHA</strong> and type <strong>BRAVO</strong>. Each of these types has a property that is the "ID" for the object. No ID is duplicated within the class, so for any given ID, there is at most one <strong>ALPHA</strong> and one <strong>BRAVO</strong> instance. What I need to do is divide them into 3 categories:</p> <ol> <li>Instances of the ID in <strong>ALPHA</strong> which do not appear in the <strong>BRAVO</strong> collection;</li> <li>Instances of the ID in <strong>BRAVO</strong> which do not appear in the <strong>ALPHA</strong> collection;</li> <li>Instances of the ID which appear in both collections. </li> </ol> <p>In all 3 cases, I need to have the actual objects from the collections at hand for subsequent manipulation. </p> <p>I know for the #3 case, I can do something like:</p> <pre><code> var myCorrelatedItems = myAlphaItems.Join(myBravoItems, alpha =&gt; alpha.Id, beta =&gt; beta.Id, (inner, outer) =&gt; new { alpha = inner, beta = outer }); </code></pre> <p>I can also write code for the #1 and #2 cases which look something like</p> <pre><code>var myUnmatchedAlphas = myAlphaItems.Where(alpha=&gt;!myBravoItems.Any(bravo=&gt;alpha.Id==bravo.Id)); </code></pre> <p>And similarly for unMatchedBravos. Unfortunately, this would result in iterating the collection of alphas (which may be very large!) many times, and the collection of bravos (which may also be very large!) many times as well. </p> <p>Is there any way to unify these query concepts so as to minimize iteration over the lists? These collections can have thousands of items.</p>
 

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