These are my simplified domain classes.
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;}
}
This is my mapping class. But it doesn't work.
public class ProductCategoryMap : EntityTypeConfiguration<ProductCategory>
{
public ProductCategoryMap()
{
ToTable("ProductCategory");
HasKey(pc => pc.ProductId);
HasKey(pc => pc.CategoryId);
}
}
How should I map these classes to provide, so that one product can be seen in multiple categories?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…