Class Employee
{ EmployeeID,Name,Designation,DateOfJoin }
Class SalaryDetails
{ EmployeeID, HRA,DA,Basic,NetSalary }
and then i added Collections of data's using List
How to find 3rd highest netsalary using LINQ query ...
I want result is ID,Name,Designation,Basic,NetSalary. So here, I want use join, groupby
How can get it ?
VulpesPosted Aug 27, 2013, 9:53 AM
var query = (from e in employees join s in salaries on e.EmployeeID equals s.EmployeeID orderby s.NetSalary descending select new {e.EmployeeID, e.Name, e.Designation, s.Basic, s.NetSalary}).ElementAt(2);
Incidentally, if there are several employees who have the joint third highest net salary and you want the whole group of them, then you can use:
VulpesPosted Aug 28, 2013, 4:44 PM
I don't really know of a better way to do this using LINQ though I suppose instead of ElementAt(n - 1) you could use Skip(n - 1).Take(1) though I doubt whether it's more efficient internally.
VijayPosted Aug 28, 2013, 1:10 AM
Please let me know whether it having alternative way to get nth Highest Salary.... other possible ways