Update : sorry for the confusion, the second linq statement for emWeight is redundant.
Hi Cetan, Naomi. Many thanks for your help.
I had this originally, but it breaks at runtime when there are not EMTransactions (which can happen).
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);
decimal? detailsWeight = 0;
detailsWeight = context.TransactionDetails.Where(r => (r.TransactionHeaders_Id == transactionHeaders_Id)).Sum(r => r.Weight);
return emWeight ?? 0 - detailsWeight ?? 0;
}
I guess in a "if-you-can't-beat'm-join'm" frame of mind I will split it into the query and the summing. So much for the functional programming fans. :)
If things have the tendency to go your way, do not worry. It won't last. Jules Renard.