What is difference between into and let keyword in LINQ?

Into – This is used to store the results of a group, join or select clause into a temporary variable. It hides the previous range variable and create a temporary range variable which you can be used further.

DataContext context = new DataContext();
var q = from emp in context.tblEmployee group emp by new {
	emp.Salary, emp.EmpId
}
into groupingEmp let avgsalary = (groupingEmp.Sum(gEmp = > gEmp.Salary) / groupingEmp.Count()) where groupingEmp.Key.Salary == avgsalary select new {
	groupingEmp.Key.Salary, groupingEmp.Key.EmpId
};

 Let – This is used to store the result of a sub expression into a new variable. It doesn’t hide the previous range variable and create a new variable which can be used further with previous variable.

Tagged , . Bookmark the permalink.

Leave a Reply