• 用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 }); 

  • 相关阅读:
    线程中死锁的demo
    发布.net core程序碰到的问题
    .net core Identity学习(三) 第三方认证接入
    .net Identity学习(二)OAuth
    .net core Identity学习(一)注册登录
    Git常用操作
    log4net使用
    c#中的Quartz
    jquery中的deferred
    .net core应用部署在IIS上
  • 原文地址:https://www.cnblogs.com/firekylin/p/2023115.html
Copyright © 2020-2023  润新知