如何使用Linq to Entity Framework选择最大值和最小值 [英] How To Select Max Value And Minimum Value Using Linq to Entity Framework
本文介绍了如何使用Linq to Entity Framework选择最大值和最小值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
美好的一天,我需要你的帮助
我想从数据库中选择最大值和最小值...
i在数据库中有这个信息
名称金额
john 20000
sarah 3000
kehinde 4444
johnson 200000
我的代码背后是
// 使用linq到实体框架
var rept =( from c in nameentity.name
其中 c.name == John
选择 c).ToList();
这将得到john的所有值并将它们发送到gridview但我想要显示最大值和最小值像这样的数据库
名称金额最低限额
价值
约翰20000 3000 200000
i有很多关于数据库的信息..感谢您的时间。我很欣赏
解决方案
尝试这样的事情:
var rept_max =( from c in nameentity.name
其中 c.name == John
选择 c).Max(c = > c.amount);
var rept_min =(来自 c in nameentity.name
其中 c.name == < span class =code-string> John
选择 c).Min(c = > c.amount);
与上述相同.....
rept_max =(来自nameentity.name中的c
其中c.name ==John
select c.amount).Max();
var rept_min =(来自nameentity.name中的c
其中c.name ==John
select c.amount).Min();
good day all, I need your help
I want to select the maximum and minimum value from the database ...
i have this this information in the database
name amount
john 20000
sarah 3000
kehinde 4444
johnson 200000
my code behind is
// using linq to entity framework
var rept = (from c in nameentity.name
where c.name == "John"
select c).ToList();
this get all all the values of john and sends them to the gridview but i want to show the maximum and mini value in the database like this
name amount minimum maximum
value value
john 20000 3000 200000
i have so many of the information on the database .. thanks for your time. i do appreciate
解决方案
Try something like this :
var rept_max = (from c in nameentity.name where c.name == "John" select c).Max(c => c.amount); var rept_min = (from c in nameentity.name where c.name == "John" select c).Min(c => c.amount);
Same as above.....
rept_max = (from c in nameentity.name
where c.name == "John"
select c.amount).Max();
var rept_min = (from c in nameentity.name
where c.name == "John"
select c.amount).Min();
这篇关于如何使用Linq to Entity Framework选择最大值和最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文