Hello,
I am new in LINQ. There is a query given below. I want to know that what is the meaning of 'into g' in 2nd line and 'g.key' in 4th line.
//To achieve Select CategoryId, Count(CategoryID) As FieldName From ProductMst Group By CategoryId you need
to write follofing linq Query
var Result14 = from p in db.ProductMst
group p by p.CategoryID into g
select new {
CategoryId = g.Key,
FieldName = g.Count()
};

Shuvojit HalderPosted Jul 14, 2015, 12:47 AM
Nilesh JadavPosted Jul 14, 2015, 1:02 AM
Rajeev PunhaniPosted Jul 14, 2015, 12:55 AM
Upendra Pratap ShahiPosted Jul 14, 2015, 12:54 AM
Into
The Into keyword allows creating a temporary variable to store the results of a group, join, or select clause into a new variable.
Hide Copy Code
var em = from e in emp
group e by new{ e.DeptId}
into gEmp
where gEmp.Count() > 1
select new { gEmp.Key.DeptId, salary = gEmp.Sum(t => t.Salary) };
In the above query, after applying into on grouping, it creates a IGrouping type gEmp variable, which is used to apply the next filter.
Note: Into is used when you want to perform an operation on grouped data.
Key-
· The key consists of three parts, implemented by a Tuple[^] class.
· The three items of the key represent the three sort criteria: position, capital letter, element string as lower case.
· To achieve the 1st criterion, strings with only lower letters have the "capital letter position" set toint.MaxValue, leading to the correct sort constraint for these cases.
· The IComparer implementation of the Compare method is straight forward with this key: compare the 1st criterion, if equal go to the 2nd, if that is still equal, take the last one.
Manoj BhoirPosted Jul 14, 2015, 12:48 AM
selectkeyword,intowill end the scope.When used with the
joinkeyword,intowill add a variable containing all of the matching items from the join. (This is called a Group Join)newkeyword they are building an anonymous object with only those two fields from g with fields key and count.