Skip to content

Commit

Permalink
feat: add entity configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikoo-Asadnejad committed May 3, 2024
1 parent afc63a6 commit 655fa95
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Product.Domain.Shared.Base;

namespace Product.Domain.Shared.Entity;
namespace Product.Domain.Aggregates.Shared.User.AggregateRoot;

public class UserModel : BaseEntity
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Product.Domain.Aggregates.Category.AggregateRoot;

namespace Product.Infrastructure.Data.EntitytypeConfigurations.Category;

public class CategoryConfiguration : IEntityTypeConfiguration<CategoryModel>
{
public void Configure(EntityTypeBuilder<CategoryModel> builder)
{
builder.HasKey(c => c.Id);

builder.Property(c => c.Id)
.IsRequired()
.ValueGeneratedOnAdd();

builder.Property(c => c.Title)
.IsRequired()
.HasMaxLength(250);

builder.HasOne(c => c.SubCategory)
.WithMany()
.HasForeignKey(c => c.SubCategoryId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Product.Infrastructure.Data.EntitytypeConfigurations.ChangeHistory;

public class ChangeLogConfiguration : IEntityTypeConfiguration<Domain.Aggregates.Shared.ChangeHistory.AggregateRoot.ChangeHistory>
{
public void Configure(EntityTypeBuilder<Domain.Aggregates.Shared.ChangeHistory.AggregateRoot.ChangeHistory> builder)
{
builder.HasKey(b => b.Id);
builder.Property(b => b.RelatedEntityType)
.HasMaxLength(150);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Product.Domain.Aggregates.Shared.OutboxMessage.AggregateRoot;

namespace Product.Infrastructure.Data.EntitytypeConfigurations.OutboxMessage;

public class OutBoxMessageConfiguration : IEntityTypeConfiguration<OutBoxMessage>
{
public void Configure(EntityTypeBuilder<OutBoxMessage> builder)
{
builder.HasKey(b => b.Id);

builder.Property(b => b.Type)
.IsRequired()
.HasMaxLength(150);

builder.Property(b => b.Content)
.IsRequired();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Product.Domain.Aggregates.Category.AggregateRoot;
using Product.Domain.Aggregates.Product.AggregateRoot;

namespace Product.Infrastructure.Data.EntitytypeConfigurations.Product;

public class ProductConfiguration : IEntityTypeConfiguration<ProductModel>
{
public void Configure(EntityTypeBuilder<ProductModel> builder)
{
builder.HasKey(p => p.Id);

builder.Property(p => p.Id)
.IsRequired()
.ValueGeneratedOnAdd();

builder.Property(p => p.Title)
.IsRequired()
.HasMaxLength(250);

builder.Property(p => p.SubTitle)
.HasMaxLength(500);

builder.OwnsOne(p => p.Price);

builder.HasOne(typeof(CategoryModel))
.WithMany();

builder.HasMany(p => p.ProductComments)
.WithOne();
}
}

0 comments on commit 655fa95

Please sign in to comment.