ActionConfigurationConfiguration.cs 3.18 KB
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Rcs.Domain.Entities;

namespace Rcs.Infrastructure.DB.Configuration.Domain
{
    /// <summary>
    /// ActionConfiguration实体的EF Core配置
    /// </summary>
    public class ActionConfigurationConfiguration : IEntityTypeConfiguration<ActionConfiguration>
    {
        public void Configure(EntityTypeBuilder<ActionConfiguration> builder)
        {
            // 配置表名(已在实体上通过Table特性配置)
            builder.ToTable("action_configurations");

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

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

            builder.Property(e => e.ActionCategory)
                .HasColumnName("action_category")
                .IsRequired();

            builder.Property(e => e.ActionCategoryName)
                .HasColumnName("action_category_name")
                .HasMaxLength(100);

            builder.Property(e => e.Manufacturer)
                .HasColumnName("manufacturer")
                .HasMaxLength(100)
                .IsRequired();

            builder.Property(e => e.RobotType)
                .HasColumnName("robot_type")
                .IsRequired();

            builder.Property(e => e.ActionName)
                .HasColumnName("action_name")
                .HasMaxLength(100)
                .IsRequired();

            builder.Property(e => e.ActionDescription)
                .HasColumnName("action_description")
                .HasMaxLength(500);

            builder.Property(e => e.ExecutionScope)
                .HasColumnName("execution_scope")
                .HasColumnType("text");

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

            builder.Property(e => e.IsEnabled)
                .HasColumnName("is_enabled")
                .HasDefaultValue(true);

            builder.Property(e => e.SortOrder)
                .HasColumnName("sort_order")
                .HasDefaultValue(0);

            builder.Property(e => e.Remarks)
                .HasColumnName("remarks")
                .HasMaxLength(1000);

            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 => new { e.Manufacturer, RobotType = e.RobotType, e.ActionCategory })
                .HasDatabaseName("idx_action_config_lookup");

            builder.HasIndex(e => e.ActionName)
                .HasDatabaseName("idx_action_config_name");

            // 配置导航属性 - 一对多关系
            builder.HasMany(e => e.Parameters)
                .WithOne(p => p.ActionConfiguration)
                .HasForeignKey(p => p.ActionConfigId)
                .OnDelete(DeleteBehavior.Cascade);
        }
    }
}