title: Group By Linq Issue
body: <p>I have a List of Items . The class looks like :</p>
  
  <pre><code>public class DeviceControllerDoorInfo
  {
  
      [DataMember]
      public string DeviceControllerId { get; set; }
      [DataMember]
      public string DeviceControllerName { get; set; }
      [DataMember]
      public string DoorId { get; set; }
      [DataMember]
      public string DoorName { get; set; }
  
  }
  </code></pre>
  
  <p>And the data looks like :</p>
  
  <pre><code>DoorId   DoorName  ControllerId ControllerName
  ------   --------  ------------ --------------
  
  Door1    DoorOne   C1           C1
  Door2    DoorTwo   C1           C1
  Door3    DoorThree C2           C2
  </code></pre>
  
  <p>I want it to be converted , to look like it.</p>
  
  <pre><code>public class AccessGroupControllerDoorEntity
  {
      public string ControllerId { get; set; }
      public string ControllerName { get; set; }
  
      public List&lt;AccessGroupDoorEnity&gt; Doors { get; set; }
  }
  
  public class AccessGroupDoorEnity
  {
      public string DoorId { get; set; }
      public string DoorName { get; set; }
  }
  </code></pre>
  
  <p>Group By the <code>ControllerId</code> and then list the door items.</p>
  
  <p>How to do it ?</p>
  
  <p>I tried :</p>
  
  <pre><code>            var controllersId = allDoors.GroupBy(e =&gt; e.DeviceControllerId).Select(x =&gt; x);
  </code></pre>
  
  <p>But does it make the Doors as List ?</p>
  
  <p>I am not sure . Please help.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>In my Data Service </p>
  
  <pre><code>    private AccessGroupEntity ConvertDoorsToEntity(DeviceControllerDoorInfo[] allDoors)
      {
          // return null if the object is invalid.
          if (allDoors != null)
          {
              AccessGroupEntity entity = new AccessGroupEntity();
  
              entity.ControllerDoorItems = new List&lt;AccessGroupControllerDoorEntity&gt;();
  
              //Convert to requested format instead of the below
  
              foreach (var door in allDoors)
              {
                  entity.DoorItems.Add(new DoorInfoEntity
                  {
                      DoorId = door.DoorId,
                      DoorName = door.DoorName,
                      ControllerId = door.DeviceControllerId,
                      ControllerName = door.DeviceControllerName
                  });
  
              }
  
               return entity;
  </code></pre>
  
  <p>But instead I want <code>entity.ControllerDoorItems</code> to contain like the below grouped data :</p>
  
  <pre><code>  ControllerId -&gt; C1
    ControllerName -&gt; C1
    Doors -&gt;          2 Objects
  </code></pre>