I am working on a c# project and writing a LINQ query, in this query I need to create a group, but I know I want to use that group type, but the type of the group gives me some trouble as I am not able to cast it to my desired type.
My Query is
from emp in employees
join dept in departments
on emp.EmpID equals dept.EmpID
group dept by dept.EmpID into groupSet
select new mycustomType
{
Department = groupSet
});
You haven’t shown the signature of any of your types. We can only be guessing how your desired type might look. Next time you ask a question make sure you provide an SSCCE.
Anyway, according to your example here’s how this custom type should look like:
where
Departmentis the type of elements inside thedepartmentscollection and it assumes thatEmpIDis of type integer.Example: