Entity Framework Core: many-to-many relationship with same entity
<p>I am trying to map many-to-many relationship with the same entity. The <code>User</code> entity has an <code>IList&lt;User&gt;</code> data field for <code>Contacts</code>, which stores users' contacts/friends information:</p>

<pre><code>public class User : DomainModel
{
    public virtual IList&lt;User&gt; Contacts { get; protected set; }
    //irrelevant code omitted
}
</code></pre>

<p>When I try to use fluent API to map this many to many relationship, it gives me some trouble. Apparently, when I use <code>HasMany()</code> on the <code>user.Contacts</code> property, it has no <code>WithMany()</code> method to call next. The intellisense from Visual Studio only shows <code>WithOne()</code>, but not <code>WithMany()</code>. </p>

<pre><code>modelBuilder.Entity&lt;User&gt;().HasMany(u =&gt; u.Contacts).WithMany() 
// gives compile time error: CS1061 'CollectionNavigationBuilder&lt;User, User&gt;' does not contain a definition for 'WithMany' and no extension method 'WithMany' accepting a first argument of type 
</code></pre>

<p>So why does this happen? Is there anything I did wrong to map this many-to-many relationship?</p>