zoukankan      html  css  js  c++  java
  • 用Linq怎么实现Row_Number排序 火麒

    select row_number()over(order by total),* from adayrate
    查询到的数据是:
    1 张三 100
    2 李四 90
    3 啊舒服 90
    4 爱是 80
    5 斯蒂芬 75
    6 士大夫 75
    7 刘德华 70
    (1)这个用Linq怎么实现?


    如果需要得到下面这样的数据,该又怎么实现啊?
    1 张三 100
    2 李四 90
    2 啊舒服 90
    4 爱是 80
    5 斯蒂芬 75
    5 士大夫 75
    7 刘德华 70
    (2)这个用Linq怎么实现?


    如果需要得到下面这样的数据,该又怎么实现啊?
    1 张三 100
    2 李四 90
    2 啊舒服 90
    3 爱是 80
    4 斯蒂芬 75
    4 士大夫 75
    5 刘德华 70
    (3)这个用Linq怎么实现?
    1.
    //参考思路  这是如何实现Row_Number的
    public List<ScoreWithRank> GetHighScoresWithRank(string gameId, int count)
    {
        Guid guid = new Guid(gameId);
        using (PPGEntities entities = new PPGEntities())
        {
            var query = from s in entities.Scores
                        where s.Game.Id == guid
                        orderby s.PlayerScore descending
                        select new
                        {
                            PlayerName = s.PlayerName,
                            PlayerScore = s.PlayerScore
                        };

            return query.AsEnumerable() // Client-side from here on
                        .Select((player, index) => new ScoreWithRank()
                                {
                                    PlayerName = player.PlayerName,
                                    PlayerScore = player.PlayerScore,
                                    Rank = index + 1;
                                }
                        .ToList();

        }
    }
    2.
    start = page * rowsPerPage;
    Products.OrderByDescending(u => u.Sales.Count())
      .Skip(start)
      .Take(rowsPerPage)
      .AsEnumerable()
      .Select((u, index) => new { Product = u, Index = index + start }); 

  • 相关阅读:
    mysql数据库存放路径
    mysql 5.5安装不对容易出现问题
    bean的scope属性
    spring四种依赖注入方式
    spring依赖注入(反转控制)
    Tomcat 安装错误
    synchronized详解
    git tag命令
    vjson.hpp
    cmake添加版本号
  • 原文地址:https://www.cnblogs.com/firekylin/p/2023115.html
Copyright © 2011-2022 走看看