title: Create relationships with Entity Framework Core
body: <p>I want to build a database with Entity Framework Core. I use the command prompt and migrations to create the database. But as you can see on my diagram, I have a many-to-many relationship. How do I create this relationship with my classes below?</p>
  
  <p><a href="https://i.stack.imgur.com/bguvO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bguvO.jpg" alt="enter image description here"></a></p>
  
  <p>Code:</p>
  
  <pre><code>public class ShoppingDbContext : IdentityDbContext&lt;User&gt;
  {
      public ShoppingDbContext(DbContextOptions options) : base(options)
      {
      }
  
      protected override void OnConfiguring(DbContextOptionsBuilder     optionsBuilder)
      {
          base.OnConfiguring(optionsBuilder);
      }
  
      public DbSet&lt;Order&gt; Orders { get; set; }
      public DbSet&lt;Product&gt; Products { get; set; }
      public DbSet&lt;PartCategory&gt; PartCategory { get; set; }
      public DbSet&lt;Part&gt; Parts { get; set; }
  }
  
  public class Product 
  {
      public int ProductId { get; set; }
      public string ProductName { get; set; }
      public double Price { get; set; }
  
      public List&lt;PartCategory&gt; PartCategory { get; set; } 
  }
  
  public class PartCategory
  {
      public int PartCategoryId { get; set; }
      public string Category { get; set; }
  
      public List&lt;Part&gt; Parts { get; set; }
  }
  </code></pre>
  
  <p>//update</p>
  
  <pre><code>public class ProductPartCategory
  {
  public int ProductId { get; set; }
  public Product Product { get; set; }
  
  public int PartCategoryId { get; set; }
  public PartCategory PartCategory { get; set; }
  }
  
  public class Product 
  {
  
  public int ProductId { get; set; }
  public string ProductName { get; set; }
  public double Price { get; set; }
  public List&lt;PartCategory&gt; PartCategories{ get; set; } 
  
  }
  
   public class PartCategory
  {
  public int PartCategoryId { get; set; }
  public string Category { get; set; }
  public List&lt;Product&gt; Products { get; set; }
  
  //dont mind this propertie its for other stuff
  public List&lt;Part&gt; Parts { get; set; }
  }
  </code></pre>