using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { List<student> list = new Program().Select("王"); foreach (student data in list) { Console.WriteLine(data.sname); } Console.ReadLine(); } private DataClasses1DataContext _Context = new DataClasses1DataContext(); public List<student> Select(string name) { return _Context.student.Where(p => p.sname.StartsWith(name) || p.sname.EndsWith(name) || p.sname.IndexOf(name) != -1).ToList(); } //public List<student> Select(string name) //{ // return _Context.student.Where(p => p.sname.StartsWith(name)).ToList(); //} //public List<student> Select(string name) //{ // return _Context.student.Where(p => p.sname.IndexOf(name) != -1).ToList(); //} } }
SQl语句分组查询,倒序查询,表a表b查询,查询所有科目的成绩分数都在分数70分以上的名字
select name from score1 where chengji >70 group by name
select distinct name from score1 a where name in (select name from score1 b where chengji>70 and a.name=b.name)
查询最近一次登录时间的一条信息。倒序查询,查第一条
select top 1* from 表 order by 列名 asc desc
大家都知道Linq查询语句很像SQL的查询。
n.Name.StartsWith(Name)--相当于A% n.Name.EndsWith(Name) --相当于%A n.Name.IndexOf(Name)!=-1 --相当于%A%
var listWhere = list.Where(n=>n.Name.StartsWith(Name)||n.Name.EndsWith(Name)||n.Name.IndexOf(Name)!=-1);
或
var listWhere = list.Where(n=>n.Name.Contains(Name));