在LINQ C#中编写sum的查询 [英] To write query for sum in LINQ C#

查看:275
本文介绍了在LINQ C#中编写sum的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的桌子上有studentno字段,我想要所有学生的总和,所以PLZ帮助我在LinQ C#

i have studentno field in my table, i want sum of all the student,so plz help me in doing that in LinQ C#

推荐答案

中尝试这样做:

Try this:
FROM p in m.Items
group p by p.Id into g
select new
{
    SumTotal = g.Sum(x => x.Total),
    SumDone = g.Sum(x => x.Done)
};



发现它这里 [ ^ ]



退房:

link 1 [ ^ ]

link 2 [ ^ ]


Found it here[^]

Check out:
link 1[^]
link 2[^]


MSDN [ ^ ]会帮助你:)


我没有明白你的问题我想你想要在这种情况下计算学生数

写查询如



var id =(来自linq_obj.tablename中的a

选择a).Tolist();

int c ount = id.count();


此计数中的
给你一个学生没有
i not get your question clearly i think u want to count number of student in that case
write query like

var id=(from a in linq_obj.tablename
select a).Tolist();
int count=id.count();

in this count give u no of student


这篇关于在LINQ C#中编写sum的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆