StepActionConfiguration.cs 2.28 KB
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Rcs.Domain.Entities;

namespace Rcs.Infrastructure.DB.Configuration.Domain
{
    /// <summary>
    /// StepAction实体的EF Core配置
    /// </summary>
    public class StepActionConfiguration : IEntityTypeConfiguration<StepAction>
    {
        public void Configure(EntityTypeBuilder<StepAction> builder)
        {
            // 配置表名
            builder.ToTable("step_actions");

            // 配置主键
            builder.HasKey(e => e.ActionId);

            // 配置属性
            builder.Property(e => e.ActionId)
                .HasColumnName("action_id")
                .ValueGeneratedNever();

            builder.Property(e => e.PropertyId)
                .HasColumnName("property_id")
                .IsRequired();

            builder.Property(e => e.Type)
                .HasColumnName("type")
                .HasMaxLength(50)
                .IsRequired();

            builder.Property(e => e.StepName)
                .HasColumnName("step_name")
                .HasMaxLength(100);

            builder.Property(e => e.Description)
                .HasColumnName("description")
                .HasMaxLength(500);

            builder.Property(e => e.Order)
                .HasColumnName("order")
                .IsRequired();

            builder.Property(e => e.BlockingType)
                .HasColumnName("blocking_type")
                .IsRequired();

            builder.Property(e => e.CreatedAt)
                .HasColumnName("created_at")
                .HasColumnType("timestamp without time zone");

            builder.Property(e => e.UpdatedAt)
                .HasColumnName("updated_at")
                .HasColumnType("timestamp without time zone");

            // 配置索引
            builder.HasIndex(e => e.PropertyId)
                .HasDatabaseName("idx_action_property");

            builder.HasIndex(e => new { e.PropertyId, e.Order })
                .HasDatabaseName("idx_action_property_order");

            // 配置导航属性 - 多对一关系
            builder.HasOne(e => e.Property)
                .WithMany(p => p.Actions)
                .HasForeignKey(e => e.PropertyId)
                .OnDelete(DeleteBehavior.Cascade);
        }
    }
}