Select net value from sum of 2 columns in linq
Hi all,
I have a table called table 1 ,in that table below columns are available
ID currentqty newqty
1 null null
2. 8. 4
3. 34. 24
4. Null. Null
Need to select sum(currentqty)-sum(newqty)
In linq c#
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Jaimin ShethiyaRank #177 · 13.7K reputationPosted Aug 12, 2020, 11:41 PM EDT
try to below query
var totCurrentQty = context.TableName.Sum(x=> x.CurrentQty ?? 0);
var totNewQty = context.TableName.Sum(x=> x.NewQty ?? 0);
Thanks
Navaneeth KrishnanRank #1,172 · 1.5K reputationPosted Aug 13, 2020, 6:22 AM EDT
Farhan AhmedRank #73 · 25K reputationPosted Aug 13, 2020, 7:33 AM EDT
Jignesh KumarRank #91 · 22.9K reputationPosted Aug 10, 2020, 5:47 PM EDT