title: LINQ : select all that match a single field, merge on original
body: <p>Persuant to another question, my problem has extended a bit further. I have the following object shape ... ( I am using RavenDB, which is why I have 'strings' for identity)</p>
  
  <p>This is not as complicated as I make it sound, but it is hard to communicate in brevity, so bear with me. If this makes no sense I will try to revise it. </p>
  
  <h2>TLDR</h2>
  
  <p><code>Collection A</code> has items I want to get, without getting the items in <code>Collection B</code> that have a matching ID. The two collections do not contain the same data type.</p>
  
  <h2>Further Details</h2>
  
  <pre><code>class Entity { 
    string Id { get; set; }
  }
  interface IName {
    string Name { get; set; }
  }
  
  class Reference&lt;T&gt; where T : Entity, IName {
    public string Id { get; set; }
          public string Name { get; set; }
  
          public static implicit operator Reference&lt;T&gt;(T doc) {
              return new Reference&lt;T&gt; {
                  Id = doc.Id,
                  Name = doc.Name
              };
          }
  }
  </code></pre>
  
  <p>So then, if I have an object that has ..</p>
  
  <p><code>List&lt;Reference&lt;Product&gt;&gt;</code> I can assign products directly, and it will only store the Id/Name. This is my goal. However when it comes to list comparison this gets tricky.</p>
  
  <p>So then, assume I have an array like this ..</p>
  
  <pre><code>[
   { 
     "Id" : 1, 
     "Requirement" : { 
       "Value" : "2", "Name" : "Orders" 
      }
   },
   { 
     "Id" : 2, 
     "Requirement" : { 
       "Value" : "4", "Name" : "Orders" 
      }
   },
   { 
     "Id" : 3, 
     "Requirement" : { 
       "Value" : "6", "Name" : "Orders" 
      }
   },
   { 
     "Id" : 4, 
     "Requirement" : { 
       "Value" : "8", "Name" : "Orders" 
      }
   },
  ]
  </code></pre>
  
  <p>And this is <code>Goals</code>. Then assume an array, <code>List&lt;Reference&lt;Goal&gt;&gt;</code>. This is nothing but a list of <code>Id</code> and <code>Name</code> of goals attained. (This is just a trivialized example for the sake of figuring this out. I know it is not entirely a practical shape)</p>
  
  <p>So then, as stated in my other question (visible here : <a href="https://stackoverflow.com/questions/8657760/select-all-that-do-not-already-exist-in-destination">Select All that do not already exist in destination</a>) I wanted to get the "Goals" that were met without getting duplicates each time it was run. This was solved with a simple query..</p>
  
  <p><code>Orders.Where(o =&gt; o.Requirement.Value &gt; requirment).Except(processedOrders);</code></p>
  
  <p>That works if the target array and the source array are the same, but my 'target' is a <code>List&lt;Reference&lt;Order&gt;&gt;</code> and my source is a <code>List&lt;Goal&gt;</code>. The array works up to a point ...</p>
  
  <p>Assuming that <code>User</code> has an object <code>Notebook</code> with two arrays. <code>List&lt;Reference&lt;Goal&gt;&gt;</code> is <em>GoalsReached</em> and <code>List&lt;OrdersPlaced&gt;</code>. where <code>OrdersPlaced</code> looks something like this ..</p>
  
  <pre><code>class OrdersPlaced {
    string ProductId { get; set; }
    int Quantity { get; set; }
  }
  
  var filtered = goals.Where(n =&gt; n.Requirements.Any(r =&gt; r.Name == order.Name))
                              .Where(m =&gt; m.Requirements.Any(p =&gt; p.Total &lt;= order.Total))
                              .Select(n =&gt; n.Id)
                              .Except(user.Notebook.GoalsReached);
  </code></pre>
  
  <p>This is where the problem begins. GoalsReached is just a denormalized list of references, and cannot be back-converted to the original object without a lot of re-assembly. Is there any way to make this comparison smoother?</p>