title: Convert to Int with LINQ
body: <p>Below LINQ has a few <code>Convert.ToInt32</code> methods. But it doesn't work. Referring to the internet, it is used <code>int.Parse</code> instead of convert. Still gives error. Please show me a direction to do this.</p>
  
  <p>In below query <code>tody</code>'s data type is <code>DateTime</code> </p>
  
  <pre><code>var ds = (from a in dbSetInvHeader
            join b in dbSetCustomer on a.BusinessEntityID equals b.Id
            join c in dbSetFinancialInfo on b.Id equals c.Id
            where (a.TotalAmount - a.AppliedAmount - a.ApplyToInvoiceCreditAmount) &gt; 0
                        &amp;&amp; DbFunctions.AddDays(a.InvoiceDate, Convert.ToInt32(c.CreditPeriod)) &gt;= tody
            select new OverDueInvoices
                        {
                            CustomerName = b.Name,
                            InvoiceNo = a.InvoiceNo,
                            InvoiceAmount = a.TotalAmount - a.ApplyToInvoiceCreditAmount,
                            DueAmount = (a.TotalAmount - a.AppliedAmount - a.ApplyToInvoiceCreditAmount),
                            CreditAmount = a.ApplyToInvoiceCreditAmount,
                            NoOfDays = Convert.ToInt32(DbFunctions.DiffDays(tody, a.InvoiceDate))
                        }).ToList();
  </code></pre>
  
  <p><strong>Update :</strong>  </p>
  
  <p>The code is using Entity Framework for above LINQ throws errors:  </p>
  
  <p>When using <code>Convert.ToInt32</code>:</p>
  
  <blockquote>
    <p>"LINQ to Entities does not recognize the method 'Int32 ToInt32(System.Decimal)' method, and this method cannot be translated into a store expression."</p>
  </blockquote>
  
  <p>When using <code>int.Parse</code>:</p>
  
  <blockquote>
    <p>"LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression."</p>
  </blockquote>