title: ASP.NET MVC How to Use Many to Many Relationship Between ApplicationUser and Other Domain Class
body: <p>I am currently working on a project using ASP.NET MVC, using Entity Framework and the code-first approach. Precursor, I am pretty new to all of these so some things still don't make a whole lot of sense to me.</p>
  <p>I have made a many-to-many relationship between the ApplicationUser class and the Project class as such:</p>
  <p>IdentityModels.cs:</p>
  <pre><code>public class ApplicationUser : IdentityUser
  {
      public ICollection&lt;UserProject&gt; UserProjects { get; set; }
  }
  </code></pre>
  <p>Project.cs:</p>
  <pre><code>public class Project
  {
      [...]
      public ICollection&lt;UserProject&gt; UserProjects { get; set; }
  }
  </code></pre>
  <p>UserProject.cs:</p>
  <pre><code>public class UserProject
  {
      [Key, Column(Order = 1)]
      public string UserId { get; set; }
      [Key, Column(Order = 2)]
      public int ProjectId { get; set; }
      public ApplicationUser User { get; set; }
      public Project Project { get; set; }
  }
  </code></pre>
  <p>I created a DbSet of UserProject to my ApplicationDbContext and created a migration for this.</p>
  <p>With this being said, my question is how would I go about using this relationship? More specifically, if I wanted to display only the projects that the signed in user is assigned to, how could I go about doing that?</p>
  <p>Also, my current assumption is that if I wanted to assign projects to users, I would ultimately just need to make a new UserProject object with the given User ID and the Project IDs I want to assign them with. Would that be how it would work?</p>
  <p>Is my configuration of this relationship set up in a good way or should I consider changing it to get the above functionality?</p>
  <p>Any and all help is appreciated. Thanks!</p>