Casting für Decimal nicht unterstützt LINQ to Entities-Abfragen

Ich habe eine Datenbank-Tabelle-Transaktion (Transaktions-id, LocalAmount...). wo Datentyp für Localamount Eigenschaft ist float. AUF die UI-ich bin versucht, um wieder eine SUMME der Spalte (Localamount) in eine Zeile auf eine Schaltfläche click-Ereignis.

Habe ich verwendet dezimal statt float

Aber ich erhalte eine Fehlermeldung auf den code, wo ich bin casting zu dezimal

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.

Den

 public static IEnumerable<TransactionTotalForProfitcenter> GetTotalTransactionsForProfitcenter(int profitcenterID)
    {
        List<TransactionTotalForProfitcenter> transactions = new List<TransactionTotalForProfitcenter>();
        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) && 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 => t.LocalAmount),  
                   //the error is occurring on the following line       
                                TotalTransactionAmountInEUR = (decimal)tProfitcenter.Sum(t => t.AmountInEUR) //the error is occurring on this line 
                            }
                            ).ToList();

        }
        return transactions;

    }

Ich habe versucht, einige Optionen aus der folgenden Beiträge, aber ohne Glück.

Kann jemand darauf hinweisen, welche anderen Optionen ich kann es versuchen. Entschuldigen Sie meine wenig wissen über LINQ wenn es zu trivial.

InformationsquelleAutor shaz | 2013-02-18
Schreibe einen Kommentar