-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductEntityConfiguration.cs
38 lines (32 loc) · 1.21 KB
/
ProductEntityConfiguration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Inflow.Domain.Entities;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;
namespace Inflow.Infrastructure.Persistence.Configurations
{
internal class ProductEntityConfiguration : IEntityTypeConfiguration<Product>
{
public void Configure(EntityTypeBuilder<Product> builder)
{
builder.ToTable(nameof(Product));
builder.HasKey(p => p.Id);
builder.HasOne(p => p.Category)
.WithMany(c => c.Products)
.HasForeignKey(p => p.CategoryId);
builder.HasMany(p => p.SaleItems)
.WithOne(s => s.Product)
.HasForeignKey(p => p.ProductId);
builder.HasMany(p => p.SupplyItems)
.WithOne(si => si.Product)
.HasForeignKey(p => p.ProductId);
builder.Property(p => p.Name)
.HasMaxLength(255)
.IsRequired();
builder.Property(p => p.Description)
.HasMaxLength(500);
builder.Property(p => p.Price)
.HasColumnType("money");
builder.Property(p => p.LowQuantityAmount)
.HasDefaultValue(5);
}
}
}