This commit is contained in:
@@ -3,5 +3,7 @@
|
||||
[EntityTypeConfiguration<ProductConfiguration, Product>]
|
||||
public class Product : Models.Product
|
||||
{
|
||||
public virtual ICollection<ProductCategory> Categories { get; set; } = [];
|
||||
|
||||
public virtual ICollection<ProductPrice> Prices { get; set; } = [];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using LiteCharms.Features.MidrandBooks.Categories.Entities;
|
||||
|
||||
namespace LiteCharms.Features.MidrandBooks.Products.Entities;
|
||||
|
||||
[EntityTypeConfiguration<ProductCategoryConfiguration, ProductCategory>]
|
||||
public class ProductCategory : Models.ProductCategory
|
||||
{
|
||||
public virtual Product? Product { get; set; }
|
||||
|
||||
public virtual Category? Category { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace LiteCharms.Features.MidrandBooks.Products.Entities;
|
||||
|
||||
public sealed class ProductCategoryConfiguration : IEntityTypeConfiguration<ProductCategory>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ProductCategory> builder)
|
||||
{
|
||||
builder.ToTable("ProductCategories");
|
||||
|
||||
builder.HasKey(p => p.Id);
|
||||
builder.Property(p => p.ProductId).IsRequired();
|
||||
builder.Property(p => p.CategoryId).IsRequired();
|
||||
|
||||
builder.HasOne(p => p.Product)
|
||||
.WithMany(p => p.Categories)
|
||||
.HasForeignKey(p => p.ProductId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasOne(c => c.Category)
|
||||
.WithMany()
|
||||
.HasForeignKey(c => c.CategoryId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@ public sealed class ProductConfiguration : IEntityTypeConfiguration<Product>
|
||||
builder.Property(f => f.Description).HasMaxLength(1024);
|
||||
builder.Property(f => f.ImageUrl).HasMaxLength(1024);
|
||||
builder.Property(f => f.Enabled).HasDefaultValue(false);
|
||||
builder.Property(f => f.Categories).IsRequired(false);
|
||||
builder.Property(f => f.ThumbnailUrls).IsRequired(false);
|
||||
|
||||
builder.OwnsOne(f => f.Metadata, b => { b.ToJson(); });
|
||||
|
||||
Reference in New Issue
Block a user