Message
 
To
15/03/2017 04:47:57
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 5.0
OS:
Windows 8.1
Network:
Windows Server 2012 R2
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01649038
Message ID:
01649087
Views:
33
           decimal emWeight = context.EMTransactions.Where(r => r.TransactionHeaders_Id == transactionHeaders_Id).Sum(r => (decimal?)r.Weight) ?? 0;
            // decimal? emWeight = 0;
            // var q = context.EMTransactions.Where(r => (r.TransactionHeaders_Id == transactionHeaders_Id));
            // if ((q.Count() == 0) == false)
            // {
            //    emWeight = q.Sum(r => r.Weight);
            // }
            decimal detailsWeight = context.TransactionDetails.Where(r => (r.TransactionHeaders_Id == transactionHeaders_Id)).Sum(r => r.Weight);
            return emWeight    - detailsWeight;
This indeed works. If I'm right
Sum(r => (decimal?)r.Weight)
the (decimal?) type definition applies to Sum() because Weight is defined a non nullable in my SQL table.

Many thanks for your help.

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Previous
Next
Reply
Map
View