title: Entity Framework Core: Fluent api many-to-many
body: <p>How do I model the following: a user has many followers and follows many users. The same user has many blocked users (Twitter kinda feature).</p>
  
  <pre><code>public class ApplicationUser : IdentityUser
  {
      public virtual ICollection&lt;User&gt; Following { get; set; }
      public virtual ICollection&lt;User&gt; Followers { get; set; }
      public virtual ICollection&lt;User&gt; BlockedUsers { get; set; }
  }
  
  public class User
  {
      public ApplicationUser User { get; set; }
      public string UserId { get; set; }
      public ApplicationUser Follower { get; set; }
      public string FollowerId { get; set; }
  }
  </code></pre>
  
  <p>My implementation so far:</p>
  
  <pre><code>public void Configure(EntityTypeBuilder&lt;User&gt; builder)
  {
      builder.HasKey(k =&gt; new { k.UserId, k.FollowerId });
  
      builder.HasOne(l =&gt; l.User)
             .WithMany(a =&gt; a.Followers)
             .HasForeignKey(l =&gt; l.UserId);
  
      builder.HasOne(l =&gt; l.Follower)
             .WithMany(a =&gt; a.Following)
             .HasForeignKey(l =&gt; l.FollowerId);
  }
  </code></pre>
  
  <p>How do I implement the blocked users field?</p>
  
  <pre><code>public virtual ICollection&lt;User&gt; BlockedUsers { get; set; }
  </code></pre>