标签:
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();
标签:
原文地址:http://www.cnblogs.com/sunshuping/p/5746943.html