title: Difference between cast and as inside a select in LINQ
body: <p>This code throws exception:</p>
  
  <pre><code>var query = services
               .SomeQuery(bar).select(x =&gt; (Foo)x)
               .Where(x.PropertyOfFoo == FooState.SomeState);
  var result = query.ToList(); 
  </code></pre>
  
  <p>The exception:</p>
  
  <pre><code>Unable to cast the type...
  LINQ to Entities only supports casting EDM primitive or enumeration types.
  </code></pre>
  
  <p>This code works:</p>
  
  <pre><code>var query = services
               .SomeQuery(bar).select(x =&gt; x as Foo)
               .Where(x.PropertyOfFoo == FooState.SomeState);
  var result = query.ToList(); 
  </code></pre>
  
  <p>Why does <code>as</code> allow the conversion and <code>cast</code> does not?</p>
  
  <p>I understand that <code>as</code> will return null and cast would throw an exception if either call fails. Okay. But when I run this code:</p>
  
  <pre><code>var query = services
               .SomeQuery(bar);
  var result = query.ToList(); 
  </code></pre>
  
  <p>I get a much larger query result. Why?</p>