我如何计算在LINQ to SQL查询列值的总和? [英] How can I calculate sum of column value in linq to sql query?
本文介绍了我如何计算在LINQ to SQL查询列值的总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在写这个查询:
VAR QUERY2 =(从behzad.Compare_closed_numbers_in_CRM_and_Billing_system_detail_counters
,其中p p .fileid == point.id
选择新的
{
p.count
})ToArray的()。
我该怎么植入的?谢谢。
< DIV CLASS =h2_lin>解决方案
如果计数字段类型为int试试这个:
INT总和= behzad.Compare_closed_numbers_in_CRM_and_Billing_system_detail_counters
。凡(T => t.fileid == point.id)
。选择(T => t.Count ?? 0).SUM();
如果计数字段是为nvarchar(最大)
试试这个:
INT总和= behzad.Compare_closed_numbers_in_CRM_and_Billing_system_detail_counters
。凡(T => t.fileid ==点.ID)
。选择(T => Convert.ToInt32(t.Count))之和()。
I'm write this query:
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();
in count column have any value,and I want to sum all of the count value. For example:
how can I implant that?thanks.
解决方案
If count field is int try this:
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();
If count field is nvarchar(max)
try this:
int sum = behzad.Compare_closed_numbers_in_CRM_and_Billing_system_detail_counters
.Where(t=>t.fileid == point.id)
.Select(t => Convert.ToInt32(t.Count)).Sum();
这篇关于我如何计算在LINQ to SQL查询列值的总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文