title: Select Max in Linq to Entities / Entity SQL with type conversion
body: <p>I'm trying to create some CRUD functionality for a legacy database and using the Entity Framework as an ORM tool. One table, 'Sites', has a Guid type 'Id' column which is never seen by the users and an integer type 'SiteId' which the users use to identitfy a Site.</p>
  
  <p>For god knows what reason the numeric SiteId column is of type varchar(10) in the database, but every SiteId in there is an integer and all future SiteIds will also be integers.</p>
  
  <p>For the purpose of generating a new, unique, integer type SiteId, how can i do what is effectively a 'SELECT MAX(SiteId)' using Entity SQL or Linq to Enities?? </p>
  
  <p>In other words, how can i convert every value in a column from varchar(10) into an int and select the maximum value from that set??</p>
  
  <p>This looked promising but linq can't convert the parse into a "store procedure"...</p>
  
  <pre><code>int x = entities.Sites.Max(s =&gt; int.Parse(s.SiteId));
  </code></pre>