title: The entity or complex type ... cannot be constructed in a LINQ to Entities query
body: <p>Why does one method work but not the other, when it seems they are both doing the same thing, i.e. constructing an entity. My question then, is there a way to construct the entity in a L2E query instead of having to use just Linq or indeed both?</p>
  
  <p>This works fine...</p>
  
  <pre><code>var queryToList = (from ac in ctx.AuthorisationChecks
                     where wedNumbers.Contains(ac.WedNo)
                     orderby ac.WedNo, ac.ExpAuthDate, ac.ActAuthDate
                     select new AuthorisationCheck
                     {
                         Blah = ac.Blah
                     }).ToList();
  
  model.AuthorisationChecks = queryToList.Select(x =&gt; new AuthorisationCheck
      {
          Blah = x.Blah
      }).ToList();
  </code></pre>
  
  <p>However, if i change...</p>
  
  <pre><code>var queryToList
  </code></pre>
  
  <p>to</p>
  
  <pre><code>model.AuthorisationChecks queryToList // Of type List&lt;AuthorisationCheck&gt;
  </code></pre>
  
  <p>i get the error in the Title...</p>
  
  <pre><code>The entity or complex type 'Model.AuthorisationCheck' cannot be constructed in a LINQ to Entities query.
  </code></pre>
  
  <p><strong>EDIT:</strong> 
  In the model it is simply, nothing fancy here.</p>
  
  <pre><code>public List&lt;AuthorisationCheck&gt; AuthorisationChecks { get; set; }
  </code></pre>
  
  <p><strong>EDIT2:</strong>
  Tidied this up a little to be (which works fine)...</p>
  
  <pre><code>model.AuthorisationChecks = (from ac in ctx.AuthorisationChecks
                               where wedNumbers.Contains(ac.WedNo)
                               orderby ac.WedNo, ac.ExpAuthDate, ac.ActAuthDate
                               select ac).ToList()
                               .Select(x =&gt; new AuthorisationCheck
                               {
                                   Blah = x.Blah
                               }).ToList();
  </code></pre>
  
  <p><strong>EDIT2: My Solution</strong>
  I wasn't happy with the anonymous type method and so went ahead and created a simple model containing only the properties I required to be used in the viewmodel.</p>
  
  <p>Changed the type of model.AuthorisationChecks</p>
  
  <p>from </p>
  
  <pre><code>List&lt;AuthorisationCheck&gt; // List of Entities
  </code></pre>
  
  <p>to</p>
  
  <pre><code>List&lt;AuthorisationCheckModel&gt; // List of models
  </code></pre>
  
  <p>which allows the following code to work, and without profiling it seems a lot quicker than using an anonymous type (and of course I don't cast to a list twice!).</p>
  
  <pre><code>model.AuthorisationChecks = (from ac in ctx.AuthorisationChecks
                               where wedNumbers.Contains(ac.WedNo)
                               orderby ac.WedNo, ac.ExpAuthDate, ac.ActAuthDate
                               select new AuthorisationCheckModel
                               {
                                   Blah = x.Blah
                               }).ToList();
  </code></pre>
  
  <p>P.S. I was once warned by a coworker (who used to work for Microsoft) that it isn't a good idea to directly use Entities in this manner, maybe this was one of the reasons he was thinking of, I've also noticed some odd behavior using Entities directly in other cases (mainly corruptions).</p>