Search This Blog

Sunday, August 29, 2010

LinQ -SubQuery

var EmpDetails = from comp in ListCompany
select new {
Emp = (from emp in comp.ListEmp
select new {
Company = comp.Name,
emp
})
};
------------------------------------------------------------------
var LessEmp = from Comp in ListCompany
select new {
Comp.Name,
EmpCount = Comp.ListEmp.Count
};
------------------------------------------------------
var EmpInACity = from comp in ListCompany

from emplist in comp.ListEmp
where emplist.Address.City.ToUpper().Contains("BAN")
select new {
CompName = comp.Name,
EmployeeName = emplist.Name
};
--------------------------------------------------------------------
var EmpHighSalEachComp = from comp in ListCompany
from empHigh in comp.ListEmp
where empHigh.salary == comp.ListEmp.Max(
HighEmp => HighEmp.salary)
select new {
CompanyName = comp.Name,
EmpHighName = empHigh.Name,
EmpHighSal = empHigh.salary
};
-----------------------------------------------------------------
var EmpHighSal = from comp in ListCompany
from emp in comp.ListEmp
where emp.salary == ListCompany.Max(
TComp => TComp.ListEmp.Max(HighEmp => HighEmp.salary))
select new {
CompanyName = comp.Name ,
EmployeeName = emp.Name,
EmpSal = emp.salary
};
-------------------------------------------------------------------------
var CompanyCityWise = from comp in ListCompany

from emp in comp.ListEmp
group emp by emp.Address.City into CityWiseEmp
select new {
State = CityWiseEmp.Key,
TotalSalary = CityWiseEmp.Sum(emp => emp.salary)
};
-------------------------------------------------------------------------------
var CityWiseSalary = from comp in ListCompany
select new {
comp.Name,
Emp =(from emp in comp.ListEmp
group emp by emp.Address.City into CityWiseEmp
select new {
State = CityWiseEmp.Key,
TotalSalary = CityWiseEmp.Sum(emp => emp.salary)
})
};

No comments:

Post a Comment