如何计算linq到sql查询中列值的总和?

时间:2015-09-05 11:10:16

标签: c# linq linq-to-sql

我正在写这个查询:

var query2 = (from p in behzad.Compare_closed_numbers_in_CRM_and_Billing_system_detail_counters
               where p.fileid == point.id
               select new
               {
                   p.count
               }).ToArray();
count列中的

有任何值,我想要计算所有的计数值。例如: enter image description here

我该如何植入?谢谢。

1 个答案:

答案 0 :(得分:5)

如果count字段是int,请尝试:

interface A {
    void meth() throws IOException;
}

class B implements A {
    @Override
    void meth() throws FileNotFoundException { } // compiles fine
}

class C implements A  {
    @Override
    void meth() { } // compiles fine
}

class D implements A  {
    @Override
    void meth() throws Exception { } // compile error
}

如果计数字段为int sum = behzad.Compare_closed_numbers_in_CRM_and_Billing_system_detail_counters .Where(t=>t.fileid == point.id) .Select(t => t.Count ?? 0).Sum(); ,请尝试以下操作:

nvarchar(max)