1、多条件查询:
并且 &&或者 ||var list = con.car.Where(r => r.code == "c014" || r.oil == 8.2m); 2、模糊查询1.模糊var list = con.car.Where(r => r.name.Contains("AT"));//contains包含2.开头var list = con.car.Where(r => r.name.StartsWith("皇冠"));//startswith以什么开头3.结尾var list = con.car.Where(r => r.name.EndsWith("版"));//endswith以什么结尾3、统计查询1.总个数//var count = con.car.Count();2.最大值//var Max = con.car.Max(r => r.price);3.最小值//var Min = con.car.Min(r => r.price);4.平均值//var avg = con.car.Average(r => r.price);4、分页查询
跳过,获取int count = 5;//一页显示多少条int pagecount = 1;//第几页var list = con.car.Skip(pagecount * count).Take(count);//skip:跳过多少条。take:取多少条
5、排序查询升序//var list = con.car.OrderBy(r => r.price);降序//var list = con.car.OrderByDescending(r => r.price);去重:var aaa = con.car.Select(r => r.oil).Distinct();6、外键显示return this.brand1.brand_name;//brand1是外键表名,与主键表列重名,自动加一7、组合查询var list1 = con.car.AsQueryable();var list2 = con.car.AsQueryable();var list3 = con.car.AsQueryable();if (TextBox1.Text.Trim().Length > 0)
{ list1 = list1.Where(r => r.name.Contains(TextBox1.Text.Trim()));}if (TextBox2.Text.Trim().Length > 0){ list2 = list2.Where(r => r.brand1.brand_name.Contains(TextBox2.Text.Trim()));}if (TextBox3.Text.Trim().Length > 0){ list3 = list3.Where(r => r.oil == Convert.ToDecimal(TextBox3.Text.Trim()));}var list = list1.Intersect(list2).Intersect(list3);
交集
var list = list1.Intersect(list2).Intersect(list3);-------------------------------------------------------------Repeater1.DataSource = list;Repeater1.DataBind();