2017-6-2 Linq高级查询和函数
(一)
1.Linq函数:
开头: Repeater1.DataSource = con.Users.Where(r => r.UserName.StartsWith("aa"));
.StartsWith("aa") --- 表示以什么开头
结尾:Repeater1.DataSource = con.Users.Where(r => r.NikeName.EndsWith("11"));
.EndsWith("11") ---- 以什么结尾
模糊查询(包含):Repeater1.DataSource = con.Users.Where(r=>r.NikeName.Contains("a"));
.Contains("a") --- 包含
个数,最大值,最小值,平均值,求和:
Label1.Text = con.Users.Count().ToString();
Label2.Text = con.Users.Max(r => r.ids).ToString();
Label3.Text = con.Users.Min(r => r.ids).ToString();
Label4.Text = con.Users.Average(r => r.ids).ToString();
Label5.Text = con.Users.Sum(r => r.ids).ToString();
降序:
Repeater1.DataSource = con.Users.OrderByDescending(r=>r.ids)
升序:
Repeater1.DataSource = con.Users.OrderBy(r=>r.ids)