Đây là các lớp miền được đơn giản hóa của tôi.Khuôn khổ thực thể Nhiều cột dưới dạng khóa chính bằng thông thạo Api
public class ProductCategory
{
public int ProductId { get; set; }
public int CategoryId { get; set; }
public virtual Product Product { get; set; }
public virtual Category Category { get; set; }
}
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
public int? ParentCategoryId { get; set;}
}
Đây là lớp bản đồ của tôi. Nhưng nó không hoạt động.
public class ProductCategoryMap : EntityTypeConfiguration<ProductCategory>
{
public ProductCategoryMap()
{
ToTable("ProductCategory");
HasKey(pc => pc.ProductId);
HasKey(pc => pc.CategoryId);
}
}
Làm thế nào tôi nên lập bản đồ các lớp này để cung cấp, do đó một sản phẩm có thể được nhìn thấy trong nhiều loại?