且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

与LINQ to SQL的总和列

更新时间:2023-02-10 18:23:35

假设金额列双(可能是另一种类型)

Assuming the Amount column is a double (could be another type)

double sum = Table.Select(t => t.Amount ?? 0).Sum();

double sum = Table.Sum(t => t.Amount ?? 0).Sum();



使用空coelescing接线员会给你的默认值为0,如果t.Amount为null。

Using the null coelescing operator will give you a default of 0 if t.Amount is null.