I am trying to use the code below to group employees by department. I get the error
The type ‘<>f__AnonymousType1’ exists in
both ‘Interview.Web.dll’ and ‘System.Web.dll’
when trying to enumerate the employees in a department in the default visualizer (the + icon when you hover over the variable name). I can enumerate the departments properly though.
var employees = from emp in db.Employees
join dep in db.Departments
on emp.DepartmentID equals dep.ID
select new
{
DepartmentName = dep.Name,
EmployeeName = emp.FullName
};
var depEmps = employees.GroupBy(de => de.DepartmentName);
If I add a watch on depEmps, the watch window correctly enumerates both collections, and actual code also works properly.
Grouping is something I have always avoided in LINQ, always chickening out by doing it in the DB and including a view in my model, but I suppose I have to deal with it some time.
On closer inspection, I only get the error inspecting the grouping with the default visualizer. Even in a proper watch window, and also in code, the enumerating works properly, so the grouping is working fine, just the visualizer seems a bit funny.