title: How to get max value of a string column of numbers in Entity Framework
body: <p>I have a problem here. I was trying to get the max value of an sql field as,</p>
  
  <pre><code>LastInvoiceNo = Convert.ToInt64(dbContext.InvoiceMaster.Max(e =&gt; e.InvoiceNo));
  </code></pre>
  
  <p>But it gives me wrong value since the column type of "InvoiceNo" is varchar.
  So I tried to convert it to Int64  as</p>
  
  <pre><code>LastInvoiceNo = dbContext.InvoiceMaster.Max(e =&gt;Convert.ToInt64(e.InvoiceNo));
  </code></pre>
  
  <p>and</p>
  
  <pre><code>LastInvoiceNo = dbContext.InvoiceMaster.Select(e =&gt; Int64.Parse(e.InvoiceNo)).Max();
  </code></pre>
  
  <p>But it throws an exception that </p>
  
  <blockquote>
    <p>LINQ to Entities does not recognize the method 'Int64 Parse(System.String)' method, and this method cannot be translated into a store expression.</p>
  </blockquote>