using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using CellularManagement.Domain.Entities.Device; namespace CellularManagement.Infrastructure.Configurations.Device; /// /// 用例数据库配置 /// public class TestCaseConfiguration : IEntityTypeConfiguration { /// /// 配置用例实体 /// public void Configure(EntityTypeBuilder builder) { // 表名 builder.ToTable("TestCases"); // 主键 builder.HasKey(x => x.Id); // 属性配置 builder.Property(x => x.Id) .HasMaxLength(50) .IsRequired(); builder.Property(x => x.Code) .HasMaxLength(50) .IsRequired(); builder.Property(x => x.Name) .HasMaxLength(100) .IsRequired(); builder.Property(x => x.UserCount) .IsRequired() .HasDefaultValue(1); builder.Property(x => x.UserInfoList) .HasMaxLength(4000); builder.Property(x => x.LatencyThresholdCount) .IsRequired() .HasDefaultValue(0); builder.Property(x => x.LatencyThresholdList) .HasMaxLength(2000); builder.Property(x => x.ThroughputThresholdCount) .IsRequired() .HasDefaultValue(0); builder.Property(x => x.ThroughputThresholdList) .HasMaxLength(2000); builder.Property(x => x.Description) .HasMaxLength(1000); builder.Property(x => x.Version) .HasMaxLength(20) .IsRequired(); builder.Property(x => x.VersionUpdateInfo) .HasMaxLength(500); builder.Property(x => x.IsDisabled) .IsRequired() .HasDefaultValue(false); builder.Property(x => x.Remarks) .HasMaxLength(1000); // 索引 builder.HasIndex(x => x.Code) .IsUnique() .HasFilter("\"IsDeleted\" = false"); builder.HasIndex(x => x.Version) .HasFilter("\"IsDeleted\" = false"); builder.HasIndex(x => x.Name) .HasFilter("\"IsDeleted\" = false"); builder.HasIndex(x => x.IsDisabled) .HasFilter("\"IsDeleted\" = false"); builder.HasIndex(x => x.CreatedAt) .HasFilter("\"IsDeleted\" = false"); // 软删除过滤器 builder.HasQueryFilter(x => !x.IsDeleted); } }