Select操作
比如我要查学生信息
var list=from tbstudent in mymodel.studenttable
Select tbstudent;
Join操作
比如学生表和班级表是分开的,那就需要连接班级表
var list=from tbstudent in mymodel.studenttable
join tbclass in mymodel.classtbale on tbstudent.classID equals tbclass.classID
Select tbstudent;
Where操作
比如我要通过学生名字去查学生信息
var list=from tbstudent in mymodel.studenttable
Where tbstudent.name== name
Select tbstudent;
var list= mymodel.studenttable.where(m=>m. name == name).Tolist();
Distinct操作
比如我查的学生信息里有某个重复的数据,想把重复的数据过滤掉
var list=(from tbstudent in mymodel.studenttable
Select tbstudent.name).Distinct();
var list=(from tbstudent in mymodel.studenttable
Select tbstudent).Distinct(m=>m.name);
Count/ Sum/ Min/ Max/ Avg操作
比如我想计算学生表里的数据总条数
var list=(from tbstudent in mymodel.studenttable
Select tbstudent).Count();
var list= mymodel.studenttable.Count();
比如我想计算所有学生的总分
var list=(from tbstudent in mymodel.studenttable
Select tbstudent.score).Sum();
var list= mymodel.studenttable. Select (m=>m. score).Sum();
var list= mymodel.studenttable. Sum(m=>m. score);
比如我想计算所有学生中最高分的
var list=(from tbstudent in mymodel.studenttable
Select tbstudent.score).Max();
var list= mymodel.studenttable. Max (m=>m. score);
比如我想计算所有学生中最低分的
var list=(from tbstudent in mymodel.studenttable
Select tbstudent.score).Min();
var list= mymodel.studenttable. Min (m=>m. score);
比如我想计算所有学生的平均分
var list=(from tbstudent in mymodel.studenttable
Select tbstudent.score).Avg();
var list= mymodel.studenttable. Avg (m=>m. score);
Order By操作
比如我想通过学生的ID来倒序,然后再根据倒序后的数据通过分数来倒序排序
var list=from tbstudent in mymodel.studenttable
orderby tbstudent.ID Descending, tbstudent.score Descending
Select tbstudent;
Group By操作
比如我想按照学生的成绩分为大于等于60的为一类,小于60的为一类,
var list=from tbstudent in mymodel.studenttable
Group tbstudent by tbstudent.score>=60
Select tbstudent;
var list= mymodel.Studenttable. Groupby(m=>m. score>=60);
Contains操作
比如我想把数组里的分数都查出来
int?[] arryscore={50,60,70}
var list=from tbstudent in mymodel.studenttable
where arryscore.contains(tbstudent.score)
Select tbstudent;
var list=from tbstudent in mymodel.studenttable
where (new int[] {50,60,70}.contains(tbstudent.score))
Select tbstudent;
这里是我想把除了数组里的都查出来
var list=from tbstudent in mymodel.studenttable
where !(arryscore.contains(tbstudent.score))
Select tbstudent;
var list=from tbstudent in mymodel.studenttable
where !(new int[] {50,60,70}.contains(tbstudent.score))
Select tbstudent;