title: Casting to Decimal is not supported in LINQ to Entities queries
body: <p>I have a database table Transaction (transactionID, LocalAmount...). where datatype for Localamount property is <strong>float</strong>. ON the UI I am trying to return a <strong>SUM</strong> of column (Localamount) in one row on a button click event.</p>
  <p>I have used <strong>decimal</strong> instead of <strong>float</strong></p>
  <p>However I am getting an error on the code where I am casting to <strong>decimal</strong></p>
  <pre><code>System.NotSupportedException was unhandled by user code
  Message=Casting to Decimal is not supported in LINQ to Entities queries, because the required precision and scale information cannot be inferred.
  </code></pre>
  <p>The</p>
  <pre><code> public static IEnumerable&lt;TransactionTotalForProfitcenter&gt; GetTotalTransactionsForProfitcenter(int profitcenterID)
      {
          List&lt;TransactionTotalForProfitcenter&gt; transactions = new List&lt;TransactionTotalForProfitcenter&gt;();
          using (var context = new CostReportEntities())
          {
            transactions = (from t in context.Transactions
                              join comp in context.Companies on t.CompanyID equals comp.CompanyID
                              join c in context.Countries on comp.CountryID equals c.CountryID
                              where c.CountryID.Equals(comp.CountryID) &amp;&amp; t.CompanyID == comp.CompanyID 
                               
                              join acc in context.Accounts
                                   on t.AccountID equals acc.AccountID
                              join pc in context.Profitcenters
                                  on t.ProfitcenterID equals pc.ProfitcenterID
                              group t by pc.ProfitcenterCode into tProfitcenter
                              
                              select new TransactionTotalForProfitcenter
                              {
                                  ProfitcenterCode = tProfitcenter.Key,
                      //the error is occurring on the following line           
                                  TotalTransactionAmount = (decimal)tProfitcenter.Sum(t =&gt; t.LocalAmount),  
                     //the error is occurring on the following line       
                                  TotalTransactionAmountInEUR = (decimal)tProfitcenter.Sum(t =&gt; t.AmountInEUR) //the error is occurring on this line 
                              }
                              ).ToList();
  
          }
          return transactions;
  
      }
  </code></pre>
  <p>I have tried few options from the following posts but with no luck.</p>
  <ul>
  <li><a href="https://stackoverflow.com/a/1817557/1108500">LINQ to SQL strange float behavirou</a></li>
  <li><a href="https://stackoverflow.com/a/1817557/1108500">Casting from Decimal to Float</a></li>
  </ul>
  <p>Can anyone point out what other options I may try. Excuse my little knowledge about LINQ if it is too trivial.</p>