none
Rank based to Highest Salary using LINQ RRS feed

  • Question

  • Hi,

    I want to display list of employees based their salary in descending order. Also, I have Rank property associated with Employee object which should store the rank of the employee based on his/her salary. Is it possible to do this using LINQ? If yes, then can anyone please guide me?

    Thanks,
    H
    Friday, September 18, 2009 11:37 AM

Answers

  • If you class/table name is Employees an you have a property/column named "salary" your query would be:

    var salary = from e in Employees
      orderby e.salary descending
      select e;

    As to your other part are you wanting to generate the rank property in the query based on results or it is part of the table already and you want to query by it?


    Formerly MichaelTx
    • Marked as answer by Yichun_Feng Friday, September 25, 2009 1:54 AM
    Friday, September 18, 2009 1:31 PM