title: LINQ many to many relationship - get a list of grouped objects
body: <p>I have a bit of a complicated one (for me anyway): </p>
  
  <p>I have 2 entities in a many to many relationship. </p>
  
  <pre><code>Projects       {Project_Id, ProjectName}
  Users          {User_Id, UserName} 
  Projects-Users {Id, Project_Id, User_id}   
  </code></pre>
  
  <p>A project can be assigned to more users. </p>
  
  <p>Now I want to retrieve the List of all projects (listed once) with Project_id, Name, ListOfAssignedUsers:</p>
  
  <pre><code>Id  ProjectName  Users
  1   Project1     U1, U2, U3
  2   Project2     
  3   Project3     U1
  </code></pre>
  
  <p>I can do this IN SQL, but can't figure out how to do it in LINQ! </p>
  
  <p>It's LINQ to Entity - Framework(DB first):<br>
  My classes look like this: </p>
  
  <p>public partial class Projects
      {
          public Projects()
          {
              this.Users = new HashSet();
          }</p>
  
  <pre><code>    public int Project_Id { get; set; }
      public string Name { get; set; }
  
      public virtual ICollection&lt;Users&gt; Users { get; set; }
  }
  </code></pre>
  
  <p>public partial class Users
      {
          public Users()
          {
              this.Projects = new HashSet();
          }</p>
  
  <pre><code>    public int User_Id { get; set; }
      public string UserName { get; set; }
  
      public virtual ICollection&lt;Projects&gt; Projects { get; set; }
  }
  </code></pre>
  
  <p>(I made the change with removing the id from Projects-Users and made the combo (Project_Id, User_id) the primary key of that. </p>