title: Grouping List elements and map to new model using Linq
body: <p>I have list of items that should be converted to another data structure using  Linq statements. I am able to group list, however, I cannot correctly create subelements.</p>
  
  <p>Here is my result model (simplified):</p>
  
  <pre><code>public class MyModel {
      string Name {get; set;}
      List&lt;MySubmodel&gt; Submodels {get;set;}
  }
  
  public class MySubmodel {
      string Id {get;set;}
      string Title {get;set;}
      ...
  }
  </code></pre>
  
  <p>Here is source:</p>
  
  <pre><code>public class SourceModel
          string Id {get;set;}
          string Title {get;set;}
          ...
          string Name {get;set;} // this is property for grouping
      }
  
  
  public List&lt;SourceModel&gt; src = getList();
  </code></pre>
  
  <p><code>src</code> list elements of class <code>SourceModel</code> partly match <code>MySubmodel</code> and I have a mapper that maps <code>src</code> list elements to <code>MySubmodel</code>).</p>
  
  <pre><code>IEnumerable&lt;MyModel&gt; t = from p in src
                          group p by p.Name into sl
                          select new MyModel()
                          {
                              Name = sl.Key,
                              // and I am not able to create MoelSublists object
                              ModelSublists = new List&lt;MySubmodels&gt;() 
                          };
  </code></pre>