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?
Code:
public class ShoppingDbContext : IdentityDbContext<User>
{
public ShoppingDbContext(DbContextOptions options) : base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
}
public DbSet<Order> Orders { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<PartCategory> PartCategory { get; set; }
public DbSet<Part> Parts { get; set; }
}
public class Product
{
public int ProductId { get; set; }
public string ProductName { get; set; }
public double Price { get; set; }
public List<PartCategory> PartCategory { get; set; }
}
public class PartCategory
{
public int PartCategoryId { get; set; }
public string Category { get; set; }
public List<Part> Parts { get; set; }
}
//update
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<PartCategory> PartCategories{ get; set; }
}
public class PartCategory
{
public int PartCategoryId { get; set; }
public string Category { get; set; }
public List<Product> Products { get; set; }
//dont mind this propertie its for other stuff
public List<Part> Parts { get; set; }
}