title: Select Specific Columns from Database using EF Code First
body: <p>We have a customer very large table with over <strong>500</strong> columns (i know someone does that!) </p>
  
  <p>Many of these columns are in fact <strong>foreign keys to other tables</strong>.</p>
  
  <p>We also have the requirement to <strong>eager load</strong> some of the related tables.</p>
  
  <p>Is there any way in Linq to SQL or Dynamic Linq to specify what columns to be retrieved from the database? 
  I am looking for a linq statement that actually HAS this effect on the generated SQL Statement:</p>
  
  <pre><code>SELECT Id, Name FROM Book
  </code></pre>
  
  <p>When we run the reguar query generated by EF, SQL Server throws an error that you have reached the maximum number of columns that can be selected within a query!!!</p>
  
  <p>Any help is much appreciated!</p>
  
  <hr>
  
  <p>Yes exactly this is the case, the table has 500 columns and is self referencing our tool automatically eager loads the first level relations and this hits the SQL limit on number of columns that can be queried.</p>
  
  <p>I was hoping that I can set to only load limited columns of the related Entities such as Id and Name (which is used in the UI to view the record to user)</p>
  
  <p>I guess the other option is to control what FK columns should be eager loaded. However this still remains problem for tables that has a binary or ntext column which you may not want to load all the times.</p>
  
  <p>Is there a way to hook multiple models (Entities) to the same table in Code First? We tried doing this I think the effort failed miserably. </p>