title: C# LINQ to Entities - Select specified Data from two tables, populate existing Model Classes
body: <p>I have a database and am using C# LINQ to Entities using Query Syntax.</p>
  
  <p>Each DB table has it's own Entity Framework generated model class, the DB tables and model classes are named <code>Release</code> and <code>Version</code> <em>(there are others but this is my immediate problem)</em>.</p>
  
  <p>I'm trying to load specific data into these model classes based on a query.</p>
  
  <p>Essentially I want every <code>Release</code> column &amp; row, along with its associated <code>Version</code> records populated in the Navigation Property <code>Release.Versions</code>.</p>
  
  <p>However, two crucial points here:</p>
  
  <p><strong>1) I only want certain 'Version' properties to be populated from the Query</strong>
  <em>(I only need some of the data for use in an Overview page - I can't see the point of dragging back all the data (which could be quite sizeable) if I am not using it).</em> </p>
  
  <p><strong>2) I want the query to populate the already existing Model classes of Release and Version.</strong>
  <em>(Release.Versions Navigation property being populated with the Version records with cherry picked data from point 1 above)</em></p>
  
  <p>All this I could do in a long winded way with Stored Procedures - no issue, but thought EF Linq would be quicker. Ha. Ha. Haaaa.</p>
  
  <p>So:</p>
  
  <pre><code>Release.ID            &lt;---- Primary Key
  Release.Col_1         &lt;---- Other Properties (or columns)
  Release.Col_2
  Release.Col_3
  Release.Versions      &lt;---- Navigation Property to collection of Version records for each Release.
  
  Version.ID            &lt;---- Primary Key
  Version.Release_ID    &lt;---- Foreign Key to Release Table
  Version.Col_1         &lt;---- Many properties, just want first 4 properties obtained from DB.
  Version.Col_2
  Version.Col_3
  Version.Col_4
  Version.Col_5
  Version.Col_x...
  </code></pre>
  
  <p>I just can't get the syntax right.</p>
  
  <p>This is what I have (I've tried many other variants but nothing as simple as I remember it being):</p>
  
  <pre><code>var query = (from r in context.Releases
               join v in context.Versions on r.ID equals v.Release_ID
               select r).ToList();
  
  returnedRecords= new ObservableCollection&lt;Model.Release&gt;(query);
  </code></pre>
  
  <p>I seem to remember having to use the <code>select new Release { x,y,z }</code> and then a nested <code>new Version { x, y, z}</code> - but cannot for the life of me remember how to do it, or how to get it to populate the Navigation property <code>Versions</code> within the <code>Release</code> class. </p>
  
  <p>Maybe using Lambda syntax???????</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>OK, it appears I cannot do what I thought I could do.
  So, I'm not going to use Query Syntax as most of the tutorials and documentation I can find are in Method Syntax. Plus I think Include only works with Method syntax, so seems a bit pointless using Query Syntax.</p>
  
  <p>Answer marked as correct is how I loaded the Navigation Properties.</p>