修改测试迁移
continuous-integration/drone/push Build is passing Details

IRC_NewDev
hang 2024-09-12 23:51:51 +08:00
parent c9b1e5f92a
commit 603f6e095c
15 changed files with 616 additions and 107 deletions

View File

@ -13,13 +13,15 @@ namespace IRaCIS.Core.Domain.Models
{ {
#region 导航属性 #region 导航属性
[JsonIgnore] [JsonIgnore]
[ForeignKey("SponsorId")]
public Sponsor Sponsor { get; set; }
[JsonIgnore]
[ForeignKey("CROId")]
public CRO CRO { get; set; }
[JsonIgnore]
public List<TrialBodyPart> TrialBodyPartList { get; set; } public List<TrialBodyPart> TrialBodyPartList { get; set; }
[JsonIgnore] [JsonIgnore]
public List<TaskMedicalReview> TaskMedicalReviewList { get; set; } public List<TaskMedicalReview> TaskMedicalReviewList { get; set; }
[JsonIgnore] [JsonIgnore]
public List<TaskConsistentRule> TaskConsistentRuleList { get; set; } public List<TaskConsistentRule> TaskConsistentRuleList { get; set; }
[JsonIgnore] [JsonIgnore]
@ -56,21 +58,12 @@ namespace IRaCIS.Core.Domain.Models
public List<ReadModule> ReadModuleList { get; set; } = new List<ReadModule>(); public List<ReadModule> ReadModuleList { get; set; } = new List<ReadModule>();
[JsonIgnore] [JsonIgnore]
public List<UserFeedBack> UserFeedBackList { get; set; } = new List<UserFeedBack>(); public List<UserFeedBack> UserFeedBackList { get; set; } = new List<UserFeedBack>();
[JsonIgnore] [JsonIgnore]
[ForeignKey("IndicationTypeId")] [ForeignKey("IndicationTypeId")]
public Dictionary IndicationType { get; set; } public Dictionary IndicationType { get; set; }
[JsonIgnore] [JsonIgnore]
[ForeignKey("PhaseId")] [ForeignKey("PhaseId")]
public Dictionary Phase { get; set; } public Dictionary Phase { get; set; }
[JsonIgnore]
[ForeignKey("SponsorId")]
public Sponsor Sponsor { get; set; }
[JsonIgnore]
[ForeignKey("CROId")]
public CRO CRO { get; set; }
[JsonIgnore] [JsonIgnore]
[ForeignKey("ReviewModeId")] [ForeignKey("ReviewModeId")]
public Dictionary ReviewMode { get; set; } public Dictionary ReviewMode { get; set; }

View File

@ -21,3 +21,12 @@ https://www.cnblogs.com/cqpanda/p/16815263.html
dotnet ef database update 某次迁移的前一次迁移名称 -p IRaCIS.Core.Test -c IRCContext dotnet ef database update 某次迁移的前一次迁移名称 -p IRaCIS.Core.Test -c IRCContext
dotnet ef migrations add RemoveForeignKey -p IRaCIS.Core.Test -c IRCContext -o CodeFirstTest/MSSQL/Migrations dotnet ef migrations add RemoveForeignKey -p IRaCIS.Core.Test -c IRCContext -o CodeFirstTest/MSSQL/Migrations
PGSQL Ö¸¶¨
dotnet ef migrations add testSTR -p IRaCIS.Core.Test -c PGContext -o CodeFirstTest/PGSQL/Migrations
dotnet ef migrations remove -p IRaCIS.Core.Test -c PGContext

View File

@ -1,5 +1,7 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions; using Microsoft.EntityFrameworkCore.Metadata.Conventions;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
namespace IRaCIS.Core.Test namespace IRaCIS.Core.Test
@ -17,7 +19,30 @@ namespace IRaCIS.Core.Test
.Where( .Where(
property => property.ClrType == typeof(string)))) property => property.ClrType == typeof(string))))
{ {
property.Builder.HasMaxLength(200);
// 获取 MaxLength 特性
var maxLengthAttribute = property.PropertyInfo?.GetCustomAttributes(typeof(MaxLengthAttribute), false)
.FirstOrDefault() as MaxLengthAttribute;
// 获取 StringLength 特性
var stringLengthAttribute = property.PropertyInfo?.GetCustomAttributes(typeof(StringLengthAttribute), false)
.FirstOrDefault() as StringLengthAttribute;
// 输出调试信息,看看是哪种特性生效
if (stringLengthAttribute != null)
{
//Console.WriteLine($"{property.Name}: StringLength({stringLengthAttribute.MaximumLength})");
property.Builder.HasMaxLength(stringLengthAttribute.MaximumLength);
}
else if (maxLengthAttribute != null)
{
//Console.WriteLine($"{property.Name}: MaxLength (no specific length, allowing max)");
}
else
{
//Console.WriteLine($"{property.Name}: Default length 200");
property.Builder.HasMaxLength(200);
}
} }
} }
} }

View File

@ -26,11 +26,14 @@ public partial class IRCContext : DbContext
//public virtual DbSet<ReadModule> ReadModule { get; set; } //public virtual DbSet<ReadModule> ReadModule { get; set; }
//public virtual DbSet<TestStringLength> TestStringLength { get; set; } //public virtual DbSet<TestStringLength> TestStringLength { get; set; }
public virtual DbSet<TestStr> TestStr { get; set; }
public virtual DbSet<Project> Project { get; set; } public virtual DbSet<Project> Project { get; set; }
public virtual DbSet<ProjectUser> ProjectUser { get; set; } public virtual DbSet<ProjectUser> ProjectUser { get; set; }
public virtual DbSet<ProjectUser2> ProjectUser2 { get; set; } public virtual DbSet<ProjectUser2> ProjectUser2 { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

View File

@ -0,0 +1,146 @@
// <auto-generated />
using System;
using IRaCIS.Core.Test.CodeFirstTest.MSSQL;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
{
[DbContext(typeof(IRCContext))]
[Migration("20240912145208_test")]
partial class test
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.ToTable("Project");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Name2")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<string>("OtherName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<Guid>("ProjectId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("ProjectId");
b.ToTable("ProjectUser");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser2", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("ProjectId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("ProjectId");
b.ToTable("ProjectUser2");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>
{
b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser2", b =>
{
b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
{
/// <inheritdoc />
public partial class test : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "Name",
table: "ProjectUser",
newName: "OtherName");
migrationBuilder.AddColumn<string>(
name: "Name2",
table: "ProjectUser",
type: "nvarchar(200)",
maxLength: 200,
nullable: false,
defaultValue: "");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Name2",
table: "ProjectUser");
migrationBuilder.RenameColumn(
name: "OtherName",
table: "ProjectUser",
newName: "Name");
}
}
}

View File

@ -0,0 +1,183 @@
// <auto-generated />
using System;
using IRaCIS.Core.Test.CodeFirstTest.MSSQL;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
{
[DbContext(typeof(IRCContext))]
[Migration("20240912152420_testSTR")]
partial class testSTR
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.ToTable("Project");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Name2")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<string>("OtherName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<Guid>("ProjectId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("ProjectId");
b.ToTable("ProjectUser");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser2", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("ProjectId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("ProjectId");
b.ToTable("ProjectUser2");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestStr", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<string>("DefineLength")
.IsRequired()
.HasMaxLength(400)
.HasColumnType("nvarchar(400)");
b.Property<string>("DefualtLength")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<string>("MaxLength")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.ToTable("TestStr");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>
{
b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser2", b =>
{
b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
{
/// <inheritdoc />
public partial class testSTR : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "TestStr",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
DefualtLength = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
MaxLength = table.Column<string>(type: "nvarchar(max)", nullable: false),
DefineLength = table.Column<string>(type: "nvarchar(400)", maxLength: 400, nullable: false),
CreateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
UpdateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TestStr", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "TestStr");
}
}
}

View File

@ -42,7 +42,7 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Project", (string)null); b.ToTable("Project");
}); });
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b => modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>
@ -62,7 +62,12 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.Property<Guid>("CreateUserId") b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier"); .HasColumnType("uniqueidentifier");
b.Property<string>("Name") b.Property<string>("Name2")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<string>("OtherName")
.IsRequired() .IsRequired()
.HasMaxLength(200) .HasMaxLength(200)
.HasColumnType("nvarchar(200)"); .HasColumnType("nvarchar(200)");
@ -80,7 +85,7 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.HasIndex("ProjectId"); b.HasIndex("ProjectId");
b.ToTable("ProjectUser", (string)null); b.ToTable("ProjectUser");
}); });
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser2", b => modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser2", b =>
@ -108,7 +113,44 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.HasIndex("ProjectId"); b.HasIndex("ProjectId");
b.ToTable("ProjectUser2", (string)null); b.ToTable("ProjectUser2");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestStr", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<string>("DefineLength")
.IsRequired()
.HasMaxLength(400)
.HasColumnType("nvarchar(400)");
b.Property<string>("DefualtLength")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<string>("MaxLength")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.ToTable("TestStr");
}); });
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b => modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>

View File

@ -180,5 +180,19 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL
} }
#endregion #endregion
#region 测试字符串长度
public class TestStr: BaseFullAuditEntity
{
public string DefualtLength { get; set; }
[MaxLength]
public string MaxLength { get; set; }
[StringLength(400)]
public string DefineLength { get; set;}
}
#endregion
} }

View File

@ -0,0 +1,50 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace IRaCIS.Core.Test.CodeFirstTest.PGSQL.Migrations
{
/// <summary>
/// Efcore 最新支持批量配置字符串类型长度作为保底的 官网参考https://learn.microsoft.com/zh-cn/ef/core/modeling/bulk-configuration#conventions
/// </summary>
public class MaxStringLengthConvention : IModelFinalizingConvention
{
public void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
{
foreach (var property in modelBuilder.Metadata.GetEntityTypes()
.SelectMany(
entityType => entityType.GetDeclaredProperties()
.Where(
property => property.ClrType == typeof(string))))
{
// 获取 MaxLength 特性
var maxLengthAttribute = property.PropertyInfo?.GetCustomAttributes(typeof(MaxLengthAttribute), false)
.FirstOrDefault() as MaxLengthAttribute;
// 获取 StringLength 特性
var stringLengthAttribute = property.PropertyInfo?.GetCustomAttributes(typeof(StringLengthAttribute), false)
.FirstOrDefault() as StringLengthAttribute;
// 输出调试信息,看看是哪种特性生效
if (stringLengthAttribute != null)
{
Console.WriteLine($"{property.Name}: StringLength({stringLengthAttribute.MaximumLength})");
property.Builder.HasMaxLength(stringLengthAttribute.MaximumLength);
}
else if (maxLengthAttribute != null)
{
Console.WriteLine($"{property.Name}: MaxLength (no specific length, allowing max)");
}
else
{
Console.WriteLine($"{property.Name}: Default length 200");
property.Builder.HasMaxLength(200);
}
}
}
}
}

View File

@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations.Operations;
namespace IRaCIS.Core.Test.CodeFirstTest.PGSQL.Migrations
{
public class NoForeignKeyMigrationsSqlGenerator : MigrationsSqlGenerator
{
public NoForeignKeyMigrationsSqlGenerator(
MigrationsSqlGeneratorDependencies dependencies) : base(dependencies)
{
}
protected override void Generate(Microsoft.EntityFrameworkCore.Migrations.Operations.CreateTableOperation operation, IModel? model, MigrationCommandListBuilder builder, bool terminate = true)
{
operation.ForeignKeys.Clear();
base.Generate(operation, model, builder, terminate);
}
}
}

View File

@ -1,8 +1,29 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace IRaCIS.Core.Test.PGModelFolder; namespace IRaCIS.Core.Test.CodeFirstTest.PGSQL.Migrations;
public abstract class BaseFullAuditEntity
{
[Key]
public Guid Id { get; set; }
public Guid CreateUserId { get; set; }
public DateTime CreateTime { get; set; }
public Guid UpdateUserId { get; set; }
public DateTime UpdateTime { get; set; }
}
public class TestStr : BaseFullAuditEntity
{
public string DefualtLength { get; set; }
[MaxLength]
public string MaxLength { get; set; }
[StringLength(400)]
public string DefineLength { get; set; }
}
public partial class PGContext : DbContext public partial class PGContext : DbContext
{ {
@ -15,7 +36,7 @@ public partial class PGContext : DbContext
{ {
} }
public virtual DbSet<Subject> Subjects { get; set; } public virtual DbSet<TestStr> TestStr { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseNpgsql("Host=106.14.89.110;Port=5432;Username=sa;Password=pgsql_pwd;Database=Test6_PG"); => optionsBuilder.UseNpgsql("Host=106.14.89.110;Port=5432;Username=sa;Password=pgsql_pwd;Database=Test6_PG");
@ -44,6 +65,13 @@ public partial class PGContext : DbContext
OnModelCreatingPartial(modelBuilder); OnModelCreatingPartial(modelBuilder);
} }
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
//configurationBuilder.Conventions.Add(_ => new NoForeignKeyConvention());
//针对字符串使用默认的长度配置
configurationBuilder.Conventions.Add(_ => new MaxStringLengthConvention());
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder); partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
} }

View File

@ -1,84 +0,0 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace IRaCIS.Core.Test.PGModelFolder;
public partial class Subject
{
public Guid Id { get; set; }
[MaxLength(200)]
public string LastName { get; set; }
public int StudyCount { get; set; }
public DateTime? DeletedTime { get; set; }
public DateTime? BirthDate { get; set; }
public DateTime? FirstGiveMedicineTime { get; set; }
public bool IsMissingImages { get; set; }
public string MedicalNo { get; set; }
[MaxLength(200)]
public string ShortName { get; set; }
public string Reason { get; set; }
public Guid? FinalSubjectVisitId { get; set; }
public string Height { get; set; }
[Comment("subject 编号")]
[MaxLength(100)]
public string Code { get; set; }
public int? Age { get; set; }
public string Modalities { get; set; }
public DateTime? SignDate { get; set; }
public DateTime UpdateTime { get; set; }
public Guid CreateUserId { get; set; }
public string Sex { get; set; }
public Guid? LatestSubjectVisitId { get; set; }
public bool IsEnrollmentConfirm { get; set; }
public Guid? DeleteUserId { get; set; }
public string Weight { get; set; }
public DateTime? OutEnrollmentTime { get; set; }
public DateTime CreateTime { get; set; }
public string FirstName { get; set; }
public bool IsUrgent { get; set; }
public long Status { get; set; }
public DateTime? VisitOverTime { get; set; }
public Guid UpdateUserId { get; set; }
public bool IsDeleted { get; set; }
public Guid TrialId { get; set; }
public bool IsEnrollment { get; set; }
public bool IsAssignDoctorUser { get; set; }
public bool IsReReadingOrBackInfluenceAnalysis { get; set; }
public Guid TrialSiteId { get; set; }
}

View File

@ -58,9 +58,9 @@ partial class Program
// 要生成的表名数组 // 要生成的表名数组
var tableNames = new List<string>(args); var tableNames = new List<string>(args);
var argsStr = args.ToString()??string.Empty; var argsStr = string.Join("", args) ??string.Empty;
if (argsStr.Contains(".") || argsStr.Contains("-")|| argsStr.Contains("application")|| argsStr.Contains("IR")) if ( argsStr.Contains("-")|| argsStr.Contains("application") || argsStr.Contains("Test") || argsStr.Contains("."))
{ {
tableNames = new List<string>(); tableNames = new List<string>();
} }