I have this result table returned from a query
+----------+------------+-------------------+------------+
| Id       | Name       | ApplicationUserId | JobTypeId  |
+----------+------------+-------------------+------------+
| 6000000  | A          | 4327428           | 234        |
| 6000000  | A          | 8764328           | 232        | 
| 6000001  | B          | 1238474           | 456        |
| 6000001  | B          | 8743428           | 432        |
| 6000001  | B          | 9292384           | 122        |
+----------+------------+-------------------+------------+ 
I use raw sql query of EF
like this:
db.Database.SqlQuery<Example>(query).ToList(); 
How can I extract the common values and return an object from that result table that will look like this:
[
  {
    "Id": 6000000, "Name": "A", "Therapists": 
    [
      {"Id":"4327428", "JobTypeId": 234},
      {"Id":"8764328", "JobTypeId": 232}
    ]
  },
 {
  "Id": 6000001, "Name": "B", "Therapists": 
    [
     {"Id":"1238474", "JobTypeId": 456}, 
     {"Id":"8743428","JobTypeId": 432},
     {"Id":"9292384", "JobTypeId": 122}
    ]
 }
]
The return object can be Json or any type of object
that will preserve this structure
EDIT
I managed to preform this task by 2 foreach loops
but I want something more elegant
I also used this class to hold the sql result table
public class Example 
{
    public int Id { get; set; }
 
    public string Name { get; set; }
    
    public Guid ApplicationUserId { get; set; }
    
    public int? JobTypeId { get; set; } 
}
 
    