From 70c381831dcb557c33a5f0cbc927482111bda28b Mon Sep 17 00:00:00 2001 From: hang <87227557@qq.com> Date: Wed, 11 Sep 2024 23:53:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=BF=81=E7=A7=BB=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E5=A4=96=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Convention/MaxStringLengthConvention .cs | 29 ++ ...MigrationRemoveForeignKeysSqlGenerator .cs | 30 ++ .../CodeFirstTest/MSSQL/IRCContext.cs | 23 +- .../20240911143331_testMaxLength.Designer.cs | 356 ++++++++++++++ .../20240911143331_testMaxLength.cs | 111 +++++ .../20240911144206_teststr.Designer.cs | 394 +++++++++++++++ .../Migrations/20240911144206_teststr.cs | 40 ++ ...240911151956_RemoveForeignKeys.Designer.cs | 456 ++++++++++++++++++ .../20240911151956_RemoveForeignKeys.cs | 67 +++ .../Migrations/IRCContextModelSnapshot.cs | 201 +++++++- .../CodeFirstTest/MSSQL/TrialImageDownload.cs | 41 +- 11 files changed, 1737 insertions(+), 11 deletions(-) create mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/MaxStringLengthConvention .cs create mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/MigrationRemoveForeignKeysSqlGenerator .cs create mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911143331_testMaxLength.Designer.cs create mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911143331_testMaxLength.cs create mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911144206_teststr.Designer.cs create mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911144206_teststr.cs create mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911151956_RemoveForeignKeys.Designer.cs create mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911151956_RemoveForeignKeys.cs diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/MaxStringLengthConvention .cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/MaxStringLengthConvention .cs new file mode 100644 index 000000000..e15a8e573 --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/MaxStringLengthConvention .cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Metadata.Conventions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IRaCIS.Core.Test +{ + /// + /// Efcore 最新支持批量配置字符串类型长度作为保底的 官网参考:https://learn.microsoft.com/zh-cn/ef/core/modeling/bulk-configuration#conventions + /// + public class MaxStringLengthConvention : IModelFinalizingConvention + { + public void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext context) + { + foreach (var property in modelBuilder.Metadata.GetEntityTypes() + .SelectMany( + entityType => entityType.GetDeclaredProperties() + .Where( + property => property.ClrType == typeof(string)))) + { + property.Builder.HasMaxLength(200); + } + } + } + +} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/MigrationRemoveForeignKeysSqlGenerator .cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/MigrationRemoveForeignKeysSqlGenerator .cs new file mode 100644 index 000000000..dae427d53 --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/MigrationRemoveForeignKeysSqlGenerator .cs @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations.Operations; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Convention +{ + public class MigrationRemoveForeignKeysSqlGenerator : MigrationsSqlGenerator + { + public MigrationRemoveForeignKeysSqlGenerator(MigrationsSqlGeneratorDependencies dependencies, IMigrationsAnnotationProvider migrationsAnnotations) : 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); + } + + protected override void Generate(AddForeignKeyOperation operation, IModel? model, MigrationCommandListBuilder builder, + bool terminate = true) + { + return; + } + } +} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs index 099056b6f..d8c0ed818 100644 --- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs @@ -3,7 +3,10 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using IRaCIS.Core.Test.CodeFirstTest.MSSQL; +using IRaCIS.Core.Test.CodeFirstTest.MSSQL.Convention; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.Extensions.Options; namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL; @@ -30,8 +33,20 @@ public partial class IRCContext : DbContext public virtual DbSet ReadingClinicalData { get; set; } public virtual DbSet ReadModule { get; set; } + public virtual DbSet TestStringLength { get; set; } + + public virtual DbSet Project { get; set; } + + public virtual DbSet ProjectUser { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - => optionsBuilder.UseSqlServer("Server=106.14.89.110,1433;Database=IRC_Code;User ID=sa;Password=mssql_KnTs2a;TrustServerCertificate=true"); + { + optionsBuilder.UseSqlServer("Server=106.14.89.110,1433;Database=IRC_Code;User ID=sa;Password=mssql_KnTs2a;TrustServerCertificate=true"); + + //移除外键约束 + optionsBuilder.ReplaceService(); + } protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -43,9 +58,15 @@ public partial class IRCContext : DbContext modelBuilder.ApplyConfiguration(configurationInstance); } + OnModelCreatingPartial(modelBuilder); } + protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) + { + //针对字符串使用默认的长度配置 + configurationBuilder.Conventions.Add(_ => new MaxStringLengthConvention()); + } partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911143331_testMaxLength.Designer.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911143331_testMaxLength.Designer.cs new file mode 100644 index 000000000..6afdc346a --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911143331_testMaxLength.Designer.cs @@ -0,0 +1,356 @@ +// +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("20240911143331_testMaxLength")] + partial class testMaxLength + { + /// + 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.Dictionary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ConfigTypeId") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("ConfigTypeId"); + + b.HasIndex("ParentId"); + + b.ToTable("Dictionary"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ReadModule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("ReadModule"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ReadingClinicalData", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("ReadingId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("ReadingId"); + + b.ToTable("ReadingClinicalData"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("SubjectId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("SubjectId"); + + b.ToTable("SubejectVisit"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("FinalSubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("LatestSubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("FinalSubjectVisitId"); + + b.HasIndex("LatestSubjectVisitId"); + + b.ToTable("Subject"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestNew", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("TestName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("TrialImageDownloadId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("TrialImageDownloadId"); + + b.ToTable("TestNew"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("DownloadEndTime") + .HasColumnType("datetime2"); + + b.Property("DownloadStartTime") + .HasColumnType("datetime2"); + + b.Property("ImageCount") + .HasColumnType("int"); + + b.Property("ImageSize") + .HasColumnType("bigint"); + + b.Property("ImageType") + .HasColumnType("int"); + + b.Property("IsSuccess") + .HasColumnType("bit"); + + b.Property("SubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("TrialImageDownload"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", "ConfigType") + .WithMany() + .HasForeignKey("ConfigTypeId"); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", "Parent") + .WithMany("ChildList") + .HasForeignKey("ParentId"); + + b.Navigation("ConfigType"); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ReadingClinicalData", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ReadModule", "ReadModule") + .WithMany() + .HasForeignKey("ReadingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "SubjectVisit") + .WithMany() + .HasForeignKey("ReadingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ReadModule"); + + b.Navigation("SubjectVisit"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", "Subject") + .WithMany("SubejectVisitList") + .HasForeignKey("SubjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Subject"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "FinalSubjectVisit") + .WithMany() + .HasForeignKey("FinalSubjectVisitId"); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "LatestSubjectVisit") + .WithMany() + .HasForeignKey("LatestSubjectVisitId"); + + b.Navigation("FinalSubjectVisit"); + + b.Navigation("LatestSubjectVisit"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestNew", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", null) + .WithMany("TestNewList") + .HasForeignKey("TrialImageDownloadId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", b => + { + b.Navigation("ChildList"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.Navigation("SubejectVisitList"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", b => + { + b.Navigation("TestNewList"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911143331_testMaxLength.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911143331_testMaxLength.cs new file mode 100644 index 000000000..420938bec --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911143331_testMaxLength.cs @@ -0,0 +1,111 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations +{ + /// + public partial class testMaxLength : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Name", + table: "Subject", + type: "nvarchar(200)", + maxLength: 200, + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + + migrationBuilder.AlterColumn( + name: "Code", + table: "Dictionary", + type: "nvarchar(200)", + maxLength: 200, + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + + migrationBuilder.CreateTable( + name: "ReadModule", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + CreateUserId = table.Column(type: "uniqueidentifier", nullable: false), + CreateTime = table.Column(type: "datetime2", nullable: false), + UpdateUserId = table.Column(type: "uniqueidentifier", nullable: false), + UpdateTime = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ReadModule", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ReadingClinicalData", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Code = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + ReadingId = table.Column(type: "uniqueidentifier", nullable: false), + CreateUserId = table.Column(type: "uniqueidentifier", nullable: false), + CreateTime = table.Column(type: "datetime2", nullable: false), + UpdateUserId = table.Column(type: "uniqueidentifier", nullable: false), + UpdateTime = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ReadingClinicalData", x => x.Id); + table.ForeignKey( + name: "FK_ReadingClinicalData_ReadModule_ReadingId", + column: x => x.ReadingId, + principalTable: "ReadModule", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ReadingClinicalData_SubejectVisit_ReadingId", + column: x => x.ReadingId, + principalTable: "SubejectVisit", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ReadingClinicalData_ReadingId", + table: "ReadingClinicalData", + column: "ReadingId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ReadingClinicalData"); + + migrationBuilder.DropTable( + name: "ReadModule"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Subject", + type: "nvarchar(max)", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(200)", + oldMaxLength: 200); + + migrationBuilder.AlterColumn( + name: "Code", + table: "Dictionary", + type: "nvarchar(max)", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(200)", + oldMaxLength: 200); + } + } +} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911144206_teststr.Designer.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911144206_teststr.Designer.cs new file mode 100644 index 000000000..55e35c9f0 --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911144206_teststr.Designer.cs @@ -0,0 +1,394 @@ +// +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("20240911144206_teststr")] + partial class teststr + { + /// + 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.Dictionary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ConfigTypeId") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("ConfigTypeId"); + + b.HasIndex("ParentId"); + + b.ToTable("Dictionary"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ReadModule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("ReadModule"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ReadingClinicalData", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("ReadingId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("ReadingId"); + + b.ToTable("ReadingClinicalData"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("SubjectId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("SubjectId"); + + b.ToTable("SubejectVisit"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("FinalSubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("LatestSubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("FinalSubjectVisitId"); + + b.HasIndex("LatestSubjectVisitId"); + + b.ToTable("Subject"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestNew", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("TestName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("TrialImageDownloadId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("TrialImageDownloadId"); + + b.ToTable("TestNew"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestStringLength", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("DefaultLength") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserDefineLength") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("nvarchar(300)"); + + b.Property("UserDefineText") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("TestStringLength"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("DownloadEndTime") + .HasColumnType("datetime2"); + + b.Property("DownloadStartTime") + .HasColumnType("datetime2"); + + b.Property("ImageCount") + .HasColumnType("int"); + + b.Property("ImageSize") + .HasColumnType("bigint"); + + b.Property("ImageType") + .HasColumnType("int"); + + b.Property("IsSuccess") + .HasColumnType("bit"); + + b.Property("SubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("TrialImageDownload"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", "ConfigType") + .WithMany() + .HasForeignKey("ConfigTypeId"); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", "Parent") + .WithMany("ChildList") + .HasForeignKey("ParentId"); + + b.Navigation("ConfigType"); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ReadingClinicalData", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ReadModule", "ReadModule") + .WithMany() + .HasForeignKey("ReadingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "SubjectVisit") + .WithMany() + .HasForeignKey("ReadingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ReadModule"); + + b.Navigation("SubjectVisit"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", "Subject") + .WithMany("SubejectVisitList") + .HasForeignKey("SubjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Subject"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "FinalSubjectVisit") + .WithMany() + .HasForeignKey("FinalSubjectVisitId"); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "LatestSubjectVisit") + .WithMany() + .HasForeignKey("LatestSubjectVisitId"); + + b.Navigation("FinalSubjectVisit"); + + b.Navigation("LatestSubjectVisit"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestNew", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", null) + .WithMany("TestNewList") + .HasForeignKey("TrialImageDownloadId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", b => + { + b.Navigation("ChildList"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.Navigation("SubejectVisitList"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", b => + { + b.Navigation("TestNewList"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911144206_teststr.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911144206_teststr.cs new file mode 100644 index 000000000..f479cf60c --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911144206_teststr.cs @@ -0,0 +1,40 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations +{ + /// + public partial class teststr : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "TestStringLength", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + DefaultLength = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + UserDefineLength = table.Column(type: "nvarchar(300)", maxLength: 300, nullable: false), + UserDefineText = table.Column(type: "text", maxLength: 200, nullable: false), + CreateUserId = table.Column(type: "uniqueidentifier", nullable: false), + CreateTime = table.Column(type: "datetime2", nullable: false), + UpdateUserId = table.Column(type: "uniqueidentifier", nullable: false), + UpdateTime = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_TestStringLength", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "TestStringLength"); + } + } +} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911151956_RemoveForeignKeys.Designer.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911151956_RemoveForeignKeys.Designer.cs new file mode 100644 index 000000000..86afc5129 --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911151956_RemoveForeignKeys.Designer.cs @@ -0,0 +1,456 @@ +// +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("20240911151956_RemoveForeignKeys")] + partial class RemoveForeignKeys + { + /// + 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.Dictionary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ConfigTypeId") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("ConfigTypeId"); + + b.HasIndex("ParentId"); + + b.ToTable("Dictionary"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("Project"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("ProjectId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("ProjectId"); + + b.ToTable("ProjectUser"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ReadModule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("ReadModule"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ReadingClinicalData", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("ReadingId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("ReadingId"); + + b.ToTable("ReadingClinicalData"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("SubjectId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("SubjectId"); + + b.ToTable("SubejectVisit"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("FinalSubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("LatestSubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("FinalSubjectVisitId"); + + b.HasIndex("LatestSubjectVisitId"); + + b.ToTable("Subject"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestNew", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("TestName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("TrialImageDownloadId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("TrialImageDownloadId"); + + b.ToTable("TestNew"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestStringLength", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("DefaultLength") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserDefineLength") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("nvarchar(300)"); + + b.Property("UserDefineText") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("TestStringLength"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("DownloadEndTime") + .HasColumnType("datetime2"); + + b.Property("DownloadStartTime") + .HasColumnType("datetime2"); + + b.Property("ImageCount") + .HasColumnType("int"); + + b.Property("ImageSize") + .HasColumnType("bigint"); + + b.Property("ImageType") + .HasColumnType("int"); + + b.Property("IsSuccess") + .HasColumnType("bit"); + + b.Property("SubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("TrialImageDownload"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", "ConfigType") + .WithMany() + .HasForeignKey("ConfigTypeId"); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", "Parent") + .WithMany("ChildList") + .HasForeignKey("ParentId"); + + b.Navigation("ConfigType"); + + b.Navigation("Parent"); + }); + + 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.ReadingClinicalData", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ReadModule", "ReadModule") + .WithMany() + .HasForeignKey("ReadingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "SubjectVisit") + .WithMany() + .HasForeignKey("ReadingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ReadModule"); + + b.Navigation("SubjectVisit"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", "Subject") + .WithMany("SubejectVisitList") + .HasForeignKey("SubjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Subject"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "FinalSubjectVisit") + .WithMany() + .HasForeignKey("FinalSubjectVisitId"); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "LatestSubjectVisit") + .WithMany() + .HasForeignKey("LatestSubjectVisitId"); + + b.Navigation("FinalSubjectVisit"); + + b.Navigation("LatestSubjectVisit"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestNew", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", null) + .WithMany("TestNewList") + .HasForeignKey("TrialImageDownloadId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", b => + { + b.Navigation("ChildList"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.Navigation("SubejectVisitList"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", b => + { + b.Navigation("TestNewList"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911151956_RemoveForeignKeys.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911151956_RemoveForeignKeys.cs new file mode 100644 index 000000000..8a67fbd0e --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240911151956_RemoveForeignKeys.cs @@ -0,0 +1,67 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations +{ + /// + public partial class RemoveForeignKeys : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Project", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + CreateUserId = table.Column(type: "uniqueidentifier", nullable: false), + CreateTime = table.Column(type: "datetime2", nullable: false), + UpdateUserId = table.Column(type: "uniqueidentifier", nullable: false), + UpdateTime = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Project", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ProjectUser", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + ProjectId = table.Column(type: "uniqueidentifier", nullable: false), + CreateUserId = table.Column(type: "uniqueidentifier", nullable: false), + CreateTime = table.Column(type: "datetime2", nullable: false), + UpdateUserId = table.Column(type: "uniqueidentifier", nullable: false), + UpdateTime = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ProjectUser", x => x.Id); + table.ForeignKey( + name: "FK_ProjectUser_Project_ProjectId", + column: x => x.ProjectId, + principalTable: "Project", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ProjectUser_ProjectId", + table: "ProjectUser", + column: "ProjectId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ProjectUser"); + + migrationBuilder.DropTable( + name: "Project"); + } + } +} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/IRCContextModelSnapshot.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/IRCContextModelSnapshot.cs index ffb12bafa..8a0151aca 100644 --- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/IRCContextModelSnapshot.cs +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/IRCContextModelSnapshot.cs @@ -25,11 +25,13 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", b => { b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("uniqueidentifier"); b.Property("Code") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); b.Property("ConfigTypeId") .HasColumnType("uniqueidentifier"); @@ -55,12 +57,125 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations b.HasIndex("ParentId"); - b.ToTable("Dictionary", (string)null); + b.ToTable("Dictionary"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("Project"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("ProjectId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("ProjectId"); + + b.ToTable("ProjectUser"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ReadModule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("ReadModule"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ReadingClinicalData", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("ReadingId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("ReadingId"); + + b.ToTable("ReadingClinicalData"); }); modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", b => { b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("uniqueidentifier"); b.Property("CreateTime") @@ -82,12 +197,13 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations b.HasIndex("SubjectId"); - b.ToTable("SubejectVisit", (string)null); + b.ToTable("SubejectVisit"); }); modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => { b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("uniqueidentifier"); b.Property("CreateTime") @@ -104,7 +220,8 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations b.Property("Name") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); b.Property("UpdateTime") .HasColumnType("datetime2"); @@ -118,12 +235,13 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations b.HasIndex("LatestSubjectVisitId"); - b.ToTable("Subject", (string)null); + b.ToTable("Subject"); }); modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestNew", b => { b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("uniqueidentifier"); b.Property("CreateTime") @@ -150,12 +268,51 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations b.HasIndex("TrialImageDownloadId"); - b.ToTable("TestNew", (string)null); + b.ToTable("TestNew"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestStringLength", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("DefaultLength") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserDefineLength") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("nvarchar(300)"); + + b.Property("UserDefineText") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("TestStringLength"); }); modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", b => { b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("uniqueidentifier"); b.Property("CreateTime") @@ -193,7 +350,7 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations b.HasKey("Id"); - b.ToTable("TrialImageDownload", (string)null); + b.ToTable("TrialImageDownload"); }); modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", b => @@ -211,6 +368,36 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations b.Navigation("Parent"); }); + 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.ReadingClinicalData", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ReadModule", "ReadModule") + .WithMany() + .HasForeignKey("ReadingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "SubjectVisit") + .WithMany() + .HasForeignKey("ReadingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ReadModule"); + + b.Navigation("SubjectVisit"); + }); + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", b => { b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", "Subject") diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs index 02eee8fe9..6410bc381 100644 --- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs @@ -1,6 +1,4 @@ -using IRaCIS.Core.Domain.Models; -using IRaCIS.Core.Domain.Share; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -10,6 +8,15 @@ using System.Threading.Tasks; namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL { + 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; } + } [Table("TrialImageDownload")] public class TrialImageDownload : BaseFullAuditEntity @@ -126,6 +133,34 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL } #endregion + #region 测试 字符串默认长度配置 + public class TestStringLength : BaseFullAuditEntity + { + public string DefaultLength { get; set; } + [MaxLength(300)] + public string UserDefineLength { get; set; } + + [Column(TypeName = "text")] + public string UserDefineText { get; set; } + + } + #endregion + + #region 测试生成迁移移除外键约束 + + #endregion + public class Project : BaseFullAuditEntity + { + + } + + public class ProjectUser: BaseFullAuditEntity + { + //外键 + public Guid ProjectId { get; set; } + + public Project Project { get; set; } + } }