title: Joining 2 table with LINQ to Entities
body: <p>I have two tables, for Users and Songs.  I need to JOIN them both on the UserID column and return a list to the view.  I tried writing an anonymous type but I'm getting an error about:</p>
  
  <p>'Only parameterless constructors and initializers are supported in LINQ to Entities.'</p>
  
  <p>How can I JOIN and return to list?</p>
  
  <pre><code> public class User
      {
          [Key]
          public virtual Guid UserId { get; set; }
  
          [Required]
          public virtual String Username { get; set; }
  
          [Required]
          public virtual String Email { get; set; }
  
          [Required, DataType(DataType.Password)]
          public virtual String Password { get; set; }
  
  }
  
  
  
  
  
   public class Song
      {
          public int SongId { get; set; }
  
          public virtual Guid UserId { get; set; }
  
          public string SongTitle { get; set; }
  
      }
  </code></pre>
  
  <p>I tried implementing a method like this one here:</p>
  
  <p><a href="https://stackoverflow.com/questions/5013472/what-is-the-return-type-of-my-linq-query">What is the return type of my linq query?</a></p>
  
  <p>The query I ended up with was:  </p>
  
  <pre><code>var query = from u in db.Users
                          join s in db.Songs
                          on u.UserId equals s.UserId
                          select new HomeSongList(s.SongId, s.UserId, u.Username);
  
  
              return View(query.ToList());
  </code></pre>