> 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; >>
>return emWeight - (decimal) (detailsWeight ?? 0); >>
decimal emWeight = context.EMTransactions.Where(r => (r.TransactionHeaders_Id == transactionHeaders_Id)).Sum(r => r.Weight) ?? 0;If yes, then you don't need the ?? at all ( actually what it is trying to say is since neither an int nor a decimal is a nullable type you can't apply ?? there). In your code I see a (decimal) casting which is an attempt to cast to decimal and that should really be a (decimal?).