title: Adding a list inside a list from a linq to sql query
body: <p>Hello I am trying to add carriers to my friendmodel but i am unsure how to do so.</p>
  
  <p>Here is my model:</p>
  
  <pre><code>public class FriendModel
      {
          public int? Id { get; set; }
  
          [Required]
          [StringLength(50)]
          [Display(Name = "First Name")]
          public string FirstName { get; set; }
  
          [Required]
          [StringLength(50)]
          [Display(Name = "Last Name")]
          public string LastName { get; set; }
  
          [Required]
          [StringLength(10)]
          [Display(Name = "Phone Name")]
          public string PhoneNumber { get; set; }
  
          public List&lt;CarriersModel&gt; Carriers { get; set; }  
  
          public int UserId { get; set; }
          public int? SelectedCarrier { get; set; }
      }
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>var query = from f in db.Friends
                  join uf in db.Users_Friends on f.Id equals uf.FriendId
                  join c in db.Carriers on f.CarrierId equals c.Id
                  select new {Friends = f, Users_Friends = uf, Carrier = c};
  
              var friends = new List&lt;FriendModel&gt;();
  
              foreach (var row in query)
              {
                  friends.AddRange(query.Select(friend =&gt; new FriendModel()
                  {
                      Id = friend.Friends.Id,
                      FirstName = friend.Friends.FirstName,
                      LastName = friend.Friends.LastName,
                      PhoneNumber = friend.Friends.PhoneNumber,
                      UserId = friend.Friends.Id,
                      Carriers = new List&lt;CarriersModel&gt;()
                      {
                          CarrierName = friend.Carrier.CarrierName,
                          CarrierEmail = friend.Carrier.CarrierEmail,
                      }
                  }
                  ));
              }
  </code></pre>
  
  <p>When I try to add the carriers like I do in the above code it errors. (Cannot resolve symbol). Is this not the way to do this?</p>