Converting SQL Rank() to LINQ, or alternative

前端 未结 4 1986
野趣味
野趣味 2020-12-06 06:00

I have the below SQL statement that works as desired/expected. However I would like to translate it into a LINQ statement(Lambda??) so that it will fit with the rest of my

4条回答
  •  天命终不由人
    2020-12-06 06:30

    Here's a sample that shows how I would simulate Rank() in Linq:

       var q = from s in class.student
                     orderby s.Age descending
                     select new { 
                         Name = s.name, 
                         Rank = (from o in class.student
                                 where o.mark > s.mark
                                 select o).Count() + 1 
                     };
    

提交回复
热议问题