I have the following data:
PK OrderNumber USERDEFFIELD
1 0001 10
2 0001 25
3 0002 20
4 0002 22
5 0002 NULL
6 0003 ABC123
The UserDefField column is of VARCHAR type in the database. Using LINQ, how can I get the SUM(UserDefField) per order? NULL and non-numeric values for UserDefField are to be considered as zero. The result I'm trying to get:
OrderNumber TotalQty
0001 35
0002 42
0003 0
If UserDefField is strictly nullable numeric field I know I would do this inside a foreach loop:
TotalQtyForThisOrder = orders.Sum(w => w.UserDefField ?? 0 );
But for a string field, what should be done? Thank you very much for the help.