0

Assume i have the following tables in DB

Departments

ID     Name
1      Engineering
2      Accounting
3      Sales

Employees

ID     Name   DeparmentId
1      Phill    1
2      moore    1
3      lucas    2
4      john     2
5      sophie   3
6      george   3

what i want to do is to group by Employees by Deparments. I know the standard method of grouping will group employees by either departmentID or Department Name. But i want is the grouping key must be an object having multiple properties (ID and Name). Is there away to do this? please provide me some code!

  • Implement `IEquatable interface`. Search for grouping by reference type. – Giorgi Nakeuri Apr 17 '16 at 12:07
  • @har07 mutiple columns will create an inner hierarchy but i dont want another herachy instead what i want is the each parent object (Deparmtnet) must have two properties (ID, name) so i can access the ID and Name in Ajax body – Villa Villa Apr 17 '16 at 12:08

1 Answers1

1

You can use new keyword

from f in table
group f by new { f.id, f.name} into g
select ....
Amine
  • 1,198
  • 11
  • 19