PLCConfiguration.cs 2.32 KB
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using HaHRCS.Rcs.Model.Entities;

namespace Rcs.Infrastructure.DB.Configuration.Domain
{
    /// <summary>
    /// PLC EF Core 配置
    /// </summary>
    public class PLCConfiguration : IEntityTypeConfiguration<PLC>
    {
        public void Configure(EntityTypeBuilder<PLC> builder)
        {
            // 表名
            builder.ToTable("wcs_plc");

            // 主键
            builder.HasKey(e => e.Id);

            // ==================== 主键 ====================
            builder.Property(e => e.Id)
                .HasColumnName("Id")
                .ValueGeneratedOnAdd();

            // ==================== 创建/更新信息 ====================
            builder.Property(e => e.CreateTime)
                .HasColumnName("CreateTime");

            builder.Property(e => e.CreateBy)
                .HasColumnName("CreateBy")
                .HasMaxLength(20);

            builder.Property(e => e.UpdateTime)
                .HasColumnName("UpdateTime");

            builder.Property(e => e.UpdateBy)
                .HasColumnName("UpdateBy")
                .HasMaxLength(20);

            // ==================== 业务字段 ====================
            builder.Property(e => e.Code)
                .HasColumnName("Code")
                .HasMaxLength(50);

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

            builder.Property(e => e.IP)
                .HasColumnName("IP")
                .HasMaxLength(50);

            builder.Property(e => e.Brand)
                .HasColumnName("Brand")
                .HasMaxLength(50);

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

            builder.Property(e => e.LineCode)
                .HasColumnName("LineCode")
                .HasMaxLength(50);

            builder.Property(e => e.Disable)
                .HasColumnName("Disable");

            // ==================== 索引 ====================
            builder.HasIndex(e => e.Code)
                .HasDatabaseName("idx_plc_code")
                .IsUnique();

            builder.HasIndex(e => e.IP)
                .HasDatabaseName("idx_plc_ip");
        }
    }
}