Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Coalescence blues
Message
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Coalescence blues
Versions des environnements
Environment:
C# 5.0
OS:
Windows 8.1
Network:
Windows Server 2012 R2
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01649038
Message ID:
01649038
Vues:
79
        public static decimal ComputeWeightDifference(int transactionHeaders_Id,PICSEntities context)
        {
            decimal emWeight = (decimal) context.EMTransactions.Where(r => (r.TransactionHeaders_Id == transactionHeaders_Id)).Sum(r => r.Weight) ?? 0;
            decimal? detailsWeight = 0;
            emWeight = (decimal?) context.EMTransactions.Where(r => (r.TransactionHeaders_Id == transactionHeaders_Id)).Sum(r => r.Weight) ?? 0;
            detailsWeight = context.TransactionDetails.Where(r => (r.TransactionHeaders_Id == transactionHeaders_Id)).Sum(r => r.Weight);
            return (decimal)(emWeight  - (decimal) (detailsWeight ?? 0);
        }
I'm really puzzled by this statement:
          decimal emWeight = context.EMTransactions.Where(r => (r.TransactionHeaders_Id == transactionHeaders_Id)).Sum(r => r.Weight) ?? 0;
It won't compile. CS0019 Operator '??' cannot be applied to operands of type 'decimal' and 'int'

But this does :
return emWeight  - (decimal) (detailsWeight ?? 0);
So is there a way to do is in one line, or do I first need to extract the transactions and check if there are none?

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform