title: How to join two LINQ queries
body: <p>I have two related entities with composite keys:</p>
  
  <pre><code>public class Event
  {
      public string ID1 { get; set; }
      public int ID2 { get; set; }
      public DateTime EventDate { get; set; }
      public string EventData { get; set; } 
      public string DocID1 { get; set; }
      public int DocID2 { get; set; }
  }
  
  public class EventDocument
  {
  
      public string ID1 { get; set; }
      public int ID2 { get; set; }
  
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string Number { get; set; }
  
      public virtual ICollection&lt;Event&gt; Events { get; set; }
  }
  </code></pre>
  
  <p>Is there a possibility to filter first both of them by some criteria and then to join results because of big amount of records?</p>
  
  <p>Acctually I can reach related Events when I filter EventDocuments, but I also need a possibility to filter Event and EventDocument in one time.</p>
  
  <p>I am trying to do like this:</p>
  
  <pre><code>var events = ModelContext.Events.AsNoTracking().Select(x =&gt; x);
  events = events.Where(x =&gt; x.EventData.StartsWith(FilterCriteria));
  
  
  var eventDocuments = ModelContext.EventDocuments.AsNoTracking().Select(x =&gt; x);
  eventsDocuments = eventDocuments.Where(x =&gt; x.LastName.StartsWith(FilterLastName));
  </code></pre>
  
  <p>And now I need to join these to queries and get a result - filtered and joined data from two entities</p>
  
  <p>Trying to do like this:</p>
  
  <pre><code>var result = eventDocuments.Join(events, 
                          doc =&gt; new { doc.ID1, doc.ID2 }, 
                          ev =&gt; new { cross.DocID1, cross.DocID2}, 
                          (doc, ev) =&gt; new { EventDocument = doc, Event = ev }); 
  </code></pre>