asentrafin/backend/Data/Configurations/TransactionCategoryConfigur...

27 lines
1.1 KiB
C#

using Asentrafin.Api.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Asentrafin.Api.Data.Configurations;
public class TransactionCategoryConfiguration : IEntityTypeConfiguration<TransactionCategory>
{
public void Configure(EntityTypeBuilder<TransactionCategory> builder)
{
builder.ToTable("transaction_categories");
builder.HasKey(category => category.Id);
builder.Property(category => category.Name).HasMaxLength(256).IsRequired();
builder.Property(category => category.Slug).HasMaxLength(256).IsRequired();
builder.Property(category => category.PlaidPrimary).HasMaxLength(128);
builder.Property(category => category.PlaidDetailed).HasMaxLength(128);
builder.HasIndex(category => category.Slug).IsUnique();
builder.HasIndex(category => new { category.PlaidPrimary, category.PlaidDetailed });
builder.HasOne(category => category.Parent)
.WithMany(category => category.Children)
.HasForeignKey(category => category.ParentId)
.OnDelete(DeleteBehavior.Restrict);
}
}