zoukankan      html  css  js  c++  java
  • .NET RIA Service 排序,查询(6)

    这里将独立数据处理的查询相关常用操作,这里将会使用到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 };
  • 相关阅读:
    luogu P1353 [USACO08JAN]跑步Running
    bzoj 2002: [Hnoi2010]Bounce 弹飞绵羊
    [USACO3.2]Sweet Butter
    [SDOI2009]Elaxia的路线
    [USACO5.4]Telecowmunication
    [洛谷1681]最大正方形II
    [清华集训2014]奇数国
    [洛谷2814]家谱
    [洛谷1868]饥饿的奶牛
    [HNOI2003]激光炸弹
  • 原文地址:https://www.cnblogs.com/jacle169/p/2809780.html
Copyright © 2011-2022 走看看