这里将独立数据处理的查询相关常用操作,这里将会使用到Linq语句,希望大家对Linq有一定理解,关于LInq我会独立地用一个话题去讲述它的用法,这里我将假设你已经对Linq有一定了解。
排序:
1: //以id作为排序基准,并以升序方式排列,即:123456
2: GirdView1.ItemsSource = funSLContext.FunSLUsers.OrderBy(d => d.id);
3:
4: //以id作为排序基准,并以降序方式排列,即:654321
5: GirdView1.ItemsSource = funSLContext.FunSLUsers.OrderByDescending(d => d.id);
去除重复记录:
1: //去除重复的记录
2: GirdView1.ItemsSource = funSLContext.FunSLUsers.Distinct();
单简查询:
1: //简单查询userId等于"jac"的资料
2: GirdView1.ItemsSource = from d in funSLContext.FunSLUsers
3: where d.userId == "jac"
4: select d;
自定义返回类形的查询:
1.定义一个类用以作为查询结果的自定义返回类型:
1: public class selectOut
2: {
3: public string userName { get; set; }
4: public string Address { get; set; }
5: }
2.自定义恩啊返类型的查询
1: //指定返回类型的查询,把userId等于"jac"的资料查询并以selectOut类型返回
2: //selectOut里的userName值源于查找结果的userId字段
3: //selectOut里的Address值源于查找结果的address字段
4: GirdView1.ItemsSource = from d in funSLContext.FunSLUsers
5: where d.userId == "jac"
6: select new selectOut() { userName = d.userId, Address = d.address };