SPMS_API/SPMS.Infrastructure/Persistence/Configurations/AppConfigConfiguration.cs

30 lines
1003 B
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SPMS.Domain.Entities;
namespace SPMS.Infrastructure.Persistence.Configurations;
public class AppConfigConfiguration : IEntityTypeConfiguration<AppConfig>
{
public void Configure(EntityTypeBuilder<AppConfig> builder)
{
builder.ToTable("AppConfig");
builder.HasKey(e => e.Id);
builder.Property(e => e.Id).ValueGeneratedOnAdd();
builder.Property(e => e.ServiceId).IsRequired();
builder.Property(e => e.ConfigKey).HasMaxLength(100).IsRequired();
builder.Property(e => e.ConfigValue).HasColumnType("text");
builder.Property(e => e.CreatedAt).IsRequired();
builder.Property(e => e.UpdatedAt);
builder.HasIndex(e => new { e.ServiceId, e.ConfigKey }).IsUnique();
builder.HasOne(e => e.Service)
.WithMany()
.HasForeignKey(e => e.ServiceId)
.OnDelete(DeleteBehavior.Restrict);
}
}