From a64cec987d92984effafba224704203020b1d3fd Mon Sep 17 00:00:00 2001
From: hang <872297557@qq.com>
Date: Wed, 18 Sep 2024 14:51:20 +0800
Subject: [PATCH] =?UTF-8?q?codefirst=20=E6=B5=8B=E8=AF=95=E5=AE=8C?=
=?UTF-8?q?=E6=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
IRaCIS.Core.Infra.EFCore/CodeFirst使用说明 | 33 ++-
.../NoForeignKeyMigrationsSqlGenerator.cs | 14 +-
.../IRaCIS.Core.Infra.EFCore.csproj | 4 +-
.../CodeFirstTest/CodeFirst使用说明 | 40 +--
.../Convention/DecimalPrecisionConvention.cs | 42 +++
.../NoForeignKeyMigrationsSqlGenerator.cs | 11 +-
.../CodeFirstTest/MSSQL/IRCContext.cs | 7 +-
.../20240917145100_TestNameChange.cs | 28 --
.../20240918010002_Comment.Designer.cs | 254 ------------------
.../Migrations/20240918010002_Comment.cs | 40 ---
.../20240918010449_CommentModify.Designer.cs | 253 -----------------
.../20240918010449_CommentModify.cs | 74 -----
...cs => 20240918042003_addField.Designer.cs} | 47 +---
...TestName.cs => 20240918042003_addField.cs} | 57 ++--
... => 20240918042206_addComment.Designer.cs} | 50 +++-
.../Migrations/20240918042206_addComment.cs | 58 ++++
...s => 20240918042443_addField2.Designer.cs} | 58 ++--
...ddField.cs => 20240918042443_addField2.cs} | 22 +-
.../Migrations/IRCContextModelSnapshot.cs | 93 ++-----
.../CodeFirstTest/MSSQL/TrialImageDownload.cs | 55 +++-
20 files changed, 354 insertions(+), 886 deletions(-)
create mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/DecimalPrecisionConvention.cs
delete mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240917145100_TestNameChange.cs
delete mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010002_Comment.Designer.cs
delete mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010002_Comment.cs
delete mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010449_CommentModify.Designer.cs
delete mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010449_CommentModify.cs
rename IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/{20240917145100_TestNameChange.Designer.cs => 20240918042003_addField.Designer.cs} (82%)
rename IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/{20240917144649_TestName.cs => 20240918042003_addField.cs} (56%)
rename IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/{20240912072724_addField.Designer.cs => 20240918042206_addComment.Designer.cs} (73%)
create mode 100644 IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042206_addComment.cs
rename IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/{20240917144649_TestName.Designer.cs => 20240918042443_addField2.Designer.cs} (83%)
rename IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/{20240912072724_addField.cs => 20240918042443_addField2.cs} (53%)
diff --git a/IRaCIS.Core.Infra.EFCore/CodeFirst使用说明 b/IRaCIS.Core.Infra.EFCore/CodeFirst使用说明
index 6a24debc8..f00ddbdc4 100644
--- a/IRaCIS.Core.Infra.EFCore/CodeFirst使用说明
+++ b/IRaCIS.Core.Infra.EFCore/CodeFirst使用说明
@@ -1,16 +1,25 @@
-
-
# ̨ʹ÷ʽ
1Ǩļ(add-migration init -Project IRaCIS.Core.Infra.EFCore )
-add-migration init
+ add-migration init
-Remove-Migration
+2ƳɵǨļ
+ Remove-Migration
+3ݿΪǨ
+ Update-Database
+
+4ݿΪǨƣ
+
+ Update-Database xxxName
+
+5һָ from ǨƵָ to ǨƵ SQL ű
+
+ Script-Migration from to
@@ -20,8 +29,20 @@ Remove-Migration
1Ǩļ dotnet ef migrations add Initial -s IRaCIS.Core.API -p IRaCIS.Core.Infra.EFCore -c IRaCISDBContext -o CodeFirst_MSSQL/Migrations
-dotnet ef migrations add Initial -p IRaCIS.Core.Infra.EFCore
+ dotnet ef migrations add Initial -p IRaCIS.Core.Infra.EFCore
2ɵǨļ
- dotnet ef migrations remove -p IRaCIS.Core.Infra.EFCore
\ No newline at end of file
+ dotnet ef migrations remove -p IRaCIS.Core.Infra.EFCore
+
+3Ǩļµݿ
+
+ dotnet ef database update -p IRaCIS.Core.Infra.EFCore
+
+4ݿΪǨ
+
+ dotnet ef database update xxxName -p IRaCIS.Core.Infra.EFCore
+
+5һָ from ǨƵָ to ǨƵ SQL ű
+
+ dotnet ef migrations script from to -p IRaCIS.Core.Infra.EFCore
\ No newline at end of file
diff --git a/IRaCIS.Core.Infra.EFCore/Context/Convention/NoForeignKeyMigrationsSqlGenerator.cs b/IRaCIS.Core.Infra.EFCore/Context/Convention/NoForeignKeyMigrationsSqlGenerator.cs
index 7603b8e06..148fd12ea 100644
--- a/IRaCIS.Core.Infra.EFCore/Context/Convention/NoForeignKeyMigrationsSqlGenerator.cs
+++ b/IRaCIS.Core.Infra.EFCore/Context/Convention/NoForeignKeyMigrationsSqlGenerator.cs
@@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations.Operations;
+using Microsoft.EntityFrameworkCore.Update;
namespace IRaCIS.Core.Infra.EFCore;
@@ -8,10 +9,12 @@ namespace IRaCIS.Core.Infra.EFCore;
///
/// 迁移的时候,忽略显示外键的建立,增加灵活性,同时为了兼容之前dbfirst 一个字段关联多个表
///
-public class NoForeignKeyMigrationsSqlGenerator : MigrationsSqlGenerator
+public class NoForeignKeyMigrationsSqlGenerator : SqlServerMigrationsSqlGenerator
{
- public NoForeignKeyMigrationsSqlGenerator(
- MigrationsSqlGeneratorDependencies dependencies) : base(dependencies)
+
+
+ public NoForeignKeyMigrationsSqlGenerator(MigrationsSqlGeneratorDependencies dependencies, ICommandBatchPreparer commandBatchPreparer)
+ : base(dependencies, commandBatchPreparer)
{
}
@@ -20,4 +23,9 @@ public class NoForeignKeyMigrationsSqlGenerator : MigrationsSqlGenerator
operation.ForeignKeys.Clear();
base.Generate(operation, model, builder, terminate);
}
+ protected override void Generate(AddForeignKeyOperation operation, IModel? model, MigrationCommandListBuilder builder, bool terminate = true)
+ {
+
+ }
+
}
diff --git a/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj b/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj
index 60a1b70d4..b68ba65dc 100644
--- a/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj
+++ b/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj
@@ -1,5 +1,7 @@
-
+
+ enable
+
net8.0
diff --git a/IRaCIS.Core.Test/CodeFirstTest/CodeFirst使用说明 b/IRaCIS.Core.Test/CodeFirstTest/CodeFirst使用说明
index 900b5b978..e126a2272 100644
--- a/IRaCIS.Core.Test/CodeFirstTest/CodeFirst使用说明
+++ b/IRaCIS.Core.Test/CodeFirstTest/CodeFirst使用说明
@@ -3,31 +3,33 @@
https://www.cnblogs.com/cqpanda/p/16815263.html
- # dotnet ef migrations add Ǩ -p Ŀ -c ݿ -o ǨļĿ¼
+# ʹdotnet Ǩ(dotnet ef dbcontext list -p IRaCIS.Core.Infra.EFCore )
- 1Ǩļ
- dotnet ef migrations add Initial -p IRaCIS.Core.Test -c IRCContext -o CodeFirstTest/MSSQL/Migrations
+# dotnet ef migrations add Ǩ -p Ŀ -c ݿ -o ǨļĿ¼
- 2ղɵǨļδµݿģ
- dotnet ef migrations remove -p IRaCIS.Core.Test -c IRCContext
+1Ǩļ dotnet ef migrations add xxx -s IRaCIS.Core.API -p IRaCIS.Core.Infra.EFCore -c IRaCISDBContext -o CodeFirst_MSSQL/Migrations
- 3Ǩļµݿ
- dotnet ef database update -p IRaCIS.Core.Test -c IRCContext
+ dotnet ef migrations add xxx -p IRaCIS.Core.Test -c IRCContext
- 4鿴Ǩ
- dotnet ef migrations list -p IRaCIS.Core.Test -c IRCContext
+2ɵǨļ
- 5ijθµݿǨƣԶִdown
- dotnet ef database update ijǨƵǰһǨ -p IRaCIS.Core.Test -c IRCContext
+ dotnet ef migrations remove -p IRaCIS.Core.Test -c IRCContext
- dotnet ef database update TestName -p IRaCIS.Core.Test -c IRCContext
+3Ǩļµݿ
+
+ dotnet ef database update -p IRaCIS.Core.Test -c IRCContext
+
+4ݿΪǨ
+
+ dotnet ef database update xxxName -p IRaCIS.Core.Test -c IRCContext
+
+5һָ from ǨƵָ to ǨƵ SQL ű
+
+ dotnet ef migrations script from to -p IRaCIS.Core.Test -c IRCContext
+PGSQL :
+
+ dotnet ef migrations add testSTR -p IRaCIS.Core.Test -c PGContext -o CodeFirstTest/PGSQL/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
\ No newline at end of file
+ dotnet ef migrations remove -p IRaCIS.Core.Test -c PGContext
\ No newline at end of file
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/DecimalPrecisionConvention.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/DecimalPrecisionConvention.cs
new file mode 100644
index 000000000..fa40d704e
--- /dev/null
+++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/DecimalPrecisionConvention.cs
@@ -0,0 +1,42 @@
+using Microsoft.EntityFrameworkCore.Metadata.Builders;
+using Microsoft.EntityFrameworkCore.Metadata.Conventions;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace IRaCIS.Core.Test;
+
+///
+/// 设置decimal 默认精度问题 (但是用ef迁移工具的时候,还是会提示No store type was specified for the decimal property,但是迁移文件里面体现了该配置,在dbcontext里写,那么就会没该警告)
+///
+public class DecimalPrecisionConvention : IModelFinalizingConvention
+{
+ private readonly int _precision;
+ private readonly int _scale;
+
+ public DecimalPrecisionConvention(int precision, int scale)
+ {
+ _precision = precision;
+ _scale = scale;
+ }
+
+ public void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext context)
+ {
+
+ foreach (var property in modelBuilder.Metadata.GetEntityTypes()
+ .SelectMany(
+ entityType => entityType.GetDeclaredProperties()
+ .Where(
+ property => property.ClrType == typeof(decimal) || property.ClrType == typeof(decimal?))))
+ {
+
+
+ // 设置精度和小数位数
+ property.SetPrecision(_precision);
+ property.SetScale(_scale);
+ }
+ }
+}
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/NoForeignKeyMigrationsSqlGenerator.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/NoForeignKeyMigrationsSqlGenerator.cs
index 3cc41766f..bb5cbb026 100644
--- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/NoForeignKeyMigrationsSqlGenerator.cs
+++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Convention/NoForeignKeyMigrationsSqlGenerator.cs
@@ -1,13 +1,16 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations.Operations;
+using Microsoft.EntityFrameworkCore.Update;
namespace IRaCIS.Core.Test
{
- public class NoForeignKeyMigrationsSqlGenerator : MigrationsSqlGenerator
+ public class NoForeignKeyMigrationsSqlGenerator : SqlServerMigrationsSqlGenerator
{
- public NoForeignKeyMigrationsSqlGenerator(
- MigrationsSqlGeneratorDependencies dependencies) : base(dependencies)
+
+
+ public NoForeignKeyMigrationsSqlGenerator(MigrationsSqlGeneratorDependencies dependencies, ICommandBatchPreparer commandBatchPreparer)
+ : base(dependencies, commandBatchPreparer)
{
}
@@ -18,7 +21,7 @@ namespace IRaCIS.Core.Test
}
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 9c8af85c6..26b6839f3 100644
--- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs
+++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs
@@ -34,10 +34,13 @@ public partial class IRCContext : DbContext
public virtual DbSet ProjectUser { get; set; }
public virtual DbSet ProjectUser2 { get; set; }
- public virtual DbSet TestFieldName { get; set; }
+ //public virtual DbSet TestFieldName { get; set; }
- public virtual DbSet TestComment { get; set; }
+ //public virtual DbSet TestComment { get; set; }
+
+ //public virtual DbSet TestStrDefaultValue { get; set; }
+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// 替换默认的 MigrationsSqlGenerator
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240917145100_TestNameChange.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240917145100_TestNameChange.cs
deleted file mode 100644
index 7086e78b2..000000000
--- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240917145100_TestNameChange.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Microsoft.EntityFrameworkCore.Migrations;
-
-#nullable disable
-
-namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
-{
- ///
- public partial class TestNameChange : Migration
- {
- ///
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.RenameColumn(
- name: "Name",
- table: "ProjectUser",
- newName: "Name2");
- }
-
- ///
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.RenameColumn(
- name: "Name2",
- table: "ProjectUser",
- newName: "Name");
- }
- }
-}
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010002_Comment.Designer.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010002_Comment.Designer.cs
deleted file mode 100644
index ea56ce6dd..000000000
--- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010002_Comment.Designer.cs
+++ /dev/null
@@ -1,254 +0,0 @@
-//
-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("20240918010002_Comment")]
- partial class Comment
- {
- ///
- 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("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("Code")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.Property("CreateTime")
- .HasColumnType("datetime2");
-
- b.Property("CreateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("Name2")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- 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.ProjectUser2", 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("ProjectUser2");
- });
-
- modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestComment", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("uniqueidentifier");
-
- b.Property("Code")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)")
- .HasComment("这是字段备注Code");
-
- b.Property("CreateTime")
- .HasColumnType("datetime2");
-
- b.Property("CreateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("Name")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)")
- .HasComment("这是字段备注Name");
-
- b.Property("UpdateTime")
- .HasColumnType("datetime2");
-
- b.Property("UpdateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.HasKey("Id");
-
- b.ToTable("TestComment", t =>
- {
- t.HasComment("这是类备注");
- });
- });
-
- modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestFieldName", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("uniqueidentifier");
-
- b.Property("CreateTime")
- .HasColumnType("datetime2");
-
- b.Property("CreateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("NAME1")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.Property("NAme2")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.Property("UpdateTime")
- .HasColumnType("datetime2");
-
- b.Property("UpdateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("naMe3")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.HasKey("Id");
-
- b.ToTable("TestFieldName");
- });
-
- modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestStr", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("uniqueidentifier");
-
- b.Property("CreateTime")
- .HasColumnType("datetime2");
-
- b.Property("CreateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("DefineLength")
- .IsRequired()
- .HasMaxLength(400)
- .HasColumnType("nvarchar(400)");
-
- b.Property("DefualtLength")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.Property("MaxLength")
- .IsRequired()
- .HasColumnType("nvarchar(max)");
-
- b.Property("UpdateTime")
- .HasColumnType("datetime2");
-
- b.Property("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
- }
- }
-}
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010002_Comment.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010002_Comment.cs
deleted file mode 100644
index ce24674e1..000000000
--- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010002_Comment.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-using System;
-using Microsoft.EntityFrameworkCore.Migrations;
-
-#nullable disable
-
-namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
-{
- ///
- public partial class Comment : Migration
- {
- ///
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.CreateTable(
- name: "TestComment",
- columns: table => new
- {
- Id = table.Column(type: "uniqueidentifier", nullable: false),
- Code = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false, comment: "这是字段备注Code"),
- Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false, comment: "这是字段备注Name"),
- 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_TestComment", x => x.Id);
- },
- comment: "这是类备注");
- }
-
- ///
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropTable(
- name: "TestComment");
- }
- }
-}
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010449_CommentModify.Designer.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010449_CommentModify.Designer.cs
deleted file mode 100644
index 6fc40cb71..000000000
--- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010449_CommentModify.Designer.cs
+++ /dev/null
@@ -1,253 +0,0 @@
-//
-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("20240918010449_CommentModify")]
- partial class CommentModify
- {
- ///
- 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("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("Code")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.Property("CreateTime")
- .HasColumnType("datetime2");
-
- b.Property("CreateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("Name2")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- 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.ProjectUser2", 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("ProjectUser2");
- });
-
- modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestComment", 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("Name")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)")
- .HasComment("这是字段备注Name的修改");
-
- b.Property("UpdateTime")
- .HasColumnType("datetime2");
-
- b.Property("UpdateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.HasKey("Id");
-
- b.ToTable("TestComment", t =>
- {
- t.HasComment("这是类备注的修改");
- });
- });
-
- modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestFieldName", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("uniqueidentifier");
-
- b.Property("CreateTime")
- .HasColumnType("datetime2");
-
- b.Property("CreateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("NAME1")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.Property("NAme2")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.Property("UpdateTime")
- .HasColumnType("datetime2");
-
- b.Property("UpdateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("naMe3")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.HasKey("Id");
-
- b.ToTable("TestFieldName");
- });
-
- modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestStr", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("uniqueidentifier");
-
- b.Property("CreateTime")
- .HasColumnType("datetime2");
-
- b.Property("CreateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("DefineLength")
- .IsRequired()
- .HasMaxLength(400)
- .HasColumnType("nvarchar(400)");
-
- b.Property("DefualtLength")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.Property("MaxLength")
- .IsRequired()
- .HasColumnType("nvarchar(max)");
-
- b.Property("UpdateTime")
- .HasColumnType("datetime2");
-
- b.Property("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
- }
- }
-}
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010449_CommentModify.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010449_CommentModify.cs
deleted file mode 100644
index 96d191beb..000000000
--- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918010449_CommentModify.cs
+++ /dev/null
@@ -1,74 +0,0 @@
-using Microsoft.EntityFrameworkCore.Migrations;
-
-#nullable disable
-
-namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
-{
- ///
- public partial class CommentModify : Migration
- {
- ///
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.AlterTable(
- name: "TestComment",
- comment: "这是类备注的修改",
- oldComment: "这是类备注");
-
- migrationBuilder.AlterColumn(
- name: "Name",
- table: "TestComment",
- type: "nvarchar(200)",
- maxLength: 200,
- nullable: false,
- comment: "这是字段备注Name的修改",
- oldClrType: typeof(string),
- oldType: "nvarchar(200)",
- oldMaxLength: 200,
- oldComment: "这是字段备注Name");
-
- migrationBuilder.AlterColumn(
- name: "Code",
- table: "TestComment",
- type: "nvarchar(200)",
- maxLength: 200,
- nullable: false,
- oldClrType: typeof(string),
- oldType: "nvarchar(200)",
- oldMaxLength: 200,
- oldComment: "这是字段备注Code");
- }
-
- ///
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.AlterTable(
- name: "TestComment",
- comment: "这是类备注",
- oldComment: "这是类备注的修改");
-
- migrationBuilder.AlterColumn(
- name: "Name",
- table: "TestComment",
- type: "nvarchar(200)",
- maxLength: 200,
- nullable: false,
- comment: "这是字段备注Name",
- oldClrType: typeof(string),
- oldType: "nvarchar(200)",
- oldMaxLength: 200,
- oldComment: "这是字段备注Name的修改");
-
- migrationBuilder.AlterColumn(
- name: "Code",
- table: "TestComment",
- type: "nvarchar(200)",
- maxLength: 200,
- nullable: false,
- comment: "这是字段备注Code",
- oldClrType: typeof(string),
- oldType: "nvarchar(200)",
- oldMaxLength: 200);
- }
- }
-}
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240917145100_TestNameChange.Designer.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042003_addField.Designer.cs
similarity index 82%
rename from IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240917145100_TestNameChange.Designer.cs
rename to IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042003_addField.Designer.cs
index 108267f5a..2493fc036 100644
--- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240917145100_TestNameChange.Designer.cs
+++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042003_addField.Designer.cs
@@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
{
[DbContext(typeof(IRCContext))]
- [Migration("20240917145100_TestNameChange")]
- partial class TestNameChange
+ [Migration("20240918042003_addField")]
+ partial class addField
{
///
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -98,6 +98,11 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.Property("CreateUserId")
.HasColumnType("uniqueidentifier");
+ b.Property("NewCreateName")
+ .IsRequired()
+ .HasMaxLength(200)
+ .HasColumnType("nvarchar(200)");
+
b.Property("ProjectId")
.HasColumnType("uniqueidentifier");
@@ -114,44 +119,6 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.ToTable("ProjectUser2");
});
- modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestFieldName", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("uniqueidentifier");
-
- b.Property("CreateTime")
- .HasColumnType("datetime2");
-
- b.Property("CreateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("NAME1")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.Property("NAme2")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.Property("UpdateTime")
- .HasColumnType("datetime2");
-
- b.Property("UpdateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("naMe3")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.HasKey("Id");
-
- b.ToTable("TestFieldName");
- });
-
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestStr", b =>
{
b.Property("Id")
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240917144649_TestName.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042003_addField.cs
similarity index 56%
rename from IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240917144649_TestName.cs
rename to IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042003_addField.cs
index f504d5115..b217b2306 100644
--- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240917144649_TestName.cs
+++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042003_addField.cs
@@ -6,28 +6,34 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
{
///
- public partial class TestName : Migration
+ public partial class addField : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
- migrationBuilder.CreateTable(
- name: "TestFieldName",
- columns: table => new
- {
- Id = table.Column(type: "uniqueidentifier", nullable: false),
- NAME1 = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false),
- NAme2 = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false),
- naMe3 = 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_TestFieldName", x => x.Id);
- });
+ migrationBuilder.AddColumn(
+ name: "NewCreateName",
+ table: "ProjectUser2",
+ type: "nvarchar(200)",
+ maxLength: 200,
+ nullable: false,
+ defaultValue: "");
+
+ migrationBuilder.AddColumn(
+ name: "Code",
+ table: "ProjectUser",
+ type: "nvarchar(200)",
+ maxLength: 200,
+ nullable: false,
+ defaultValue: "");
+
+ migrationBuilder.AddColumn(
+ name: "Name2",
+ table: "ProjectUser",
+ type: "nvarchar(200)",
+ maxLength: 200,
+ nullable: false,
+ defaultValue: "");
migrationBuilder.CreateTable(
name: "TestStr",
@@ -51,11 +57,20 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
///
protected override void Down(MigrationBuilder migrationBuilder)
{
- migrationBuilder.DropTable(
- name: "TestFieldName");
-
migrationBuilder.DropTable(
name: "TestStr");
+
+ migrationBuilder.DropColumn(
+ name: "NewCreateName",
+ table: "ProjectUser2");
+
+ migrationBuilder.DropColumn(
+ name: "Code",
+ table: "ProjectUser");
+
+ migrationBuilder.DropColumn(
+ name: "Name2",
+ table: "ProjectUser");
}
}
}
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912072724_addField.Designer.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042206_addComment.Designer.cs
similarity index 73%
rename from IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912072724_addField.Designer.cs
rename to IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042206_addComment.Designer.cs
index ca271c8d5..138e34153 100644
--- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912072724_addField.Designer.cs
+++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042206_addComment.Designer.cs
@@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
{
[DbContext(typeof(IRCContext))]
- [Migration("20240912072724_addField")]
- partial class addField
+ [Migration("20240918042206_addComment")]
+ partial class addComment
{
///
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -98,6 +98,12 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.Property("CreateUserId")
.HasColumnType("uniqueidentifier");
+ b.Property("NewCreateName")
+ .IsRequired()
+ .HasMaxLength(200)
+ .HasColumnType("nvarchar(200)")
+ .HasComment("NewCreateName");
+
b.Property("ProjectId")
.HasColumnType("uniqueidentifier");
@@ -114,6 +120,46 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.ToTable("ProjectUser2");
});
+ modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestStr", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uniqueidentifier");
+
+ b.Property("CreateTime")
+ .HasColumnType("datetime2");
+
+ b.Property("CreateUserId")
+ .HasColumnType("uniqueidentifier");
+
+ b.Property("DefineLength")
+ .IsRequired()
+ .HasMaxLength(400)
+ .HasColumnType("nvarchar(400)");
+
+ b.Property("DefualtLength")
+ .IsRequired()
+ .HasMaxLength(200)
+ .HasColumnType("nvarchar(200)");
+
+ b.Property("MaxLength")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("UpdateTime")
+ .HasColumnType("datetime2");
+
+ b.Property("UpdateUserId")
+ .HasColumnType("uniqueidentifier");
+
+ b.HasKey("Id");
+
+ b.ToTable("TestStr", t =>
+ {
+ t.HasComment("test commment");
+ });
+ });
+
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>
{
b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", "Project")
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042206_addComment.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042206_addComment.cs
new file mode 100644
index 000000000..3ddb20667
--- /dev/null
+++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042206_addComment.cs
@@ -0,0 +1,58 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
+{
+ ///
+ public partial class addComment : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.RenameColumn(
+ name: "Name2",
+ table: "ProjectUser",
+ newName: "Name");
+
+ migrationBuilder.AlterTable(
+ name: "TestStr",
+ comment: "test commment");
+
+ migrationBuilder.AlterColumn(
+ name: "NewCreateName",
+ table: "ProjectUser2",
+ type: "nvarchar(200)",
+ maxLength: 200,
+ nullable: false,
+ comment: "NewCreateName",
+ oldClrType: typeof(string),
+ oldType: "nvarchar(200)",
+ oldMaxLength: 200);
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.RenameColumn(
+ name: "Name",
+ table: "ProjectUser",
+ newName: "Name2");
+
+ migrationBuilder.AlterTable(
+ name: "TestStr",
+ oldComment: "test commment");
+
+ migrationBuilder.AlterColumn(
+ name: "NewCreateName",
+ table: "ProjectUser2",
+ type: "nvarchar(200)",
+ maxLength: 200,
+ nullable: false,
+ oldClrType: typeof(string),
+ oldType: "nvarchar(200)",
+ oldMaxLength: 200,
+ oldComment: "NewCreateName");
+ }
+ }
+}
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240917144649_TestName.Designer.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042443_addField2.Designer.cs
similarity index 83%
rename from IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240917144649_TestName.Designer.cs
rename to IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042443_addField2.Designer.cs
index 3ebd0d69f..a4082ff88 100644
--- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240917144649_TestName.Designer.cs
+++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042443_addField2.Designer.cs
@@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
{
[DbContext(typeof(IRCContext))]
- [Migration("20240917144649_TestName")]
- partial class TestName
+ [Migration("20240918042443_addField2")]
+ partial class addField2
{
///
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -98,6 +98,12 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.Property("CreateUserId")
.HasColumnType("uniqueidentifier");
+ b.Property("NewCreateName")
+ .IsRequired()
+ .HasMaxLength(200)
+ .HasColumnType("nvarchar(200)")
+ .HasComment("NewCreateName");
+
b.Property("ProjectId")
.HasColumnType("uniqueidentifier");
@@ -114,44 +120,6 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.ToTable("ProjectUser2");
});
- modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestFieldName", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("uniqueidentifier");
-
- b.Property("CreateTime")
- .HasColumnType("datetime2");
-
- b.Property("CreateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("NAME1")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.Property("NAme2")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.Property("UpdateTime")
- .HasColumnType("datetime2");
-
- b.Property("UpdateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("naMe3")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.HasKey("Id");
-
- b.ToTable("TestFieldName");
- });
-
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestStr", b =>
{
b.Property("Id")
@@ -184,9 +152,17 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.Property("UpdateUserId")
.HasColumnType("uniqueidentifier");
+ b.Property("UserAddField")
+ .IsRequired()
+ .HasMaxLength(200)
+ .HasColumnType("nvarchar(200)");
+
b.HasKey("Id");
- b.ToTable("TestStr");
+ b.ToTable("TestStr", t =>
+ {
+ t.HasComment("test commment");
+ });
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912072724_addField.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042443_addField2.cs
similarity index 53%
rename from IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912072724_addField.cs
rename to IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042443_addField2.cs
index d9b40bfb5..a96236956 100644
--- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240912072724_addField.cs
+++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240918042443_addField2.cs
@@ -5,22 +5,14 @@
namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
{
///
- public partial class addField : Migration
+ public partial class addField2 : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn(
- name: "Code",
- table: "ProjectUser",
- type: "nvarchar(200)",
- maxLength: 200,
- nullable: false,
- defaultValue: "");
-
- migrationBuilder.AddColumn(
- name: "Name",
- table: "ProjectUser",
+ name: "UserAddField",
+ table: "TestStr",
type: "nvarchar(200)",
maxLength: 200,
nullable: false,
@@ -31,12 +23,8 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
- name: "Code",
- table: "ProjectUser");
-
- migrationBuilder.DropColumn(
- name: "Name",
- table: "ProjectUser");
+ name: "UserAddField",
+ table: "TestStr");
}
}
}
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/IRCContextModelSnapshot.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/IRCContextModelSnapshot.cs
index 558de01a7..93171abac 100644
--- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/IRCContextModelSnapshot.cs
+++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/IRCContextModelSnapshot.cs
@@ -62,7 +62,7 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.Property("CreateUserId")
.HasColumnType("uniqueidentifier");
- b.Property("Name2")
+ b.Property("Name")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
@@ -95,6 +95,12 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.Property("CreateUserId")
.HasColumnType("uniqueidentifier");
+ b.Property("NewCreateName")
+ .IsRequired()
+ .HasMaxLength(200)
+ .HasColumnType("nvarchar(200)")
+ .HasComment("NewCreateName");
+
b.Property("ProjectId")
.HasColumnType("uniqueidentifier");
@@ -111,81 +117,6 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.ToTable("ProjectUser2");
});
- modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestComment", 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("Name")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)")
- .HasComment("这是字段备注Name的修改");
-
- b.Property("UpdateTime")
- .HasColumnType("datetime2");
-
- b.Property("UpdateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.HasKey("Id");
-
- b.ToTable("TestComment", t =>
- {
- t.HasComment("这是类备注的修改");
- });
- });
-
- modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestFieldName", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("uniqueidentifier");
-
- b.Property("CreateTime")
- .HasColumnType("datetime2");
-
- b.Property("CreateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("NAME1")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.Property("NAme2")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.Property("UpdateTime")
- .HasColumnType("datetime2");
-
- b.Property("UpdateUserId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("naMe3")
- .IsRequired()
- .HasMaxLength(200)
- .HasColumnType("nvarchar(200)");
-
- b.HasKey("Id");
-
- b.ToTable("TestFieldName");
- });
-
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestStr", b =>
{
b.Property("Id")
@@ -218,9 +149,17 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.Property("UpdateUserId")
.HasColumnType("uniqueidentifier");
+ b.Property("UserAddField")
+ .IsRequired()
+ .HasMaxLength(200)
+ .HasColumnType("nvarchar(200)");
+
b.HasKey("Id");
- b.ToTable("TestStr");
+ b.ToTable("TestStr", t =>
+ {
+ t.HasComment("test commment");
+ });
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>
diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs
index c36ea74ca..ec37ab23b 100644
--- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs
+++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs
@@ -158,13 +158,10 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL
public class ProjectUser : BaseFullAuditEntity
{
- //public string Name2 { get; set; }
-
- //public string OtherName { get; set; }
public string Code { get; set; }
- public string Name2 { get; set; }
+ public string Name { get; set; }
//外键
public Guid ProjectId { get; set; }
@@ -178,20 +175,53 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL
public Guid ProjectId { get; set; }
public Project Project { get; set; }
+
+ [Comment("NewCreateName")]
+ public string NewCreateName { get; set; }
+
}
#endregion
#region 测试字符串长度
+ [Comment("test commment4")]
public class TestStr: BaseFullAuditEntity
{
+ [Comment("test commment3")]
public string DefualtLength { get; set; }
+ [Comment("test commment1")]
[MaxLength]
public string MaxLength { get; set; }
+ [Comment("test commment2")]
[StringLength(400)]
public string DefineLength { get; set;}
+
+ }
+
+ ///
+ /// 备注
+ ///
+ public class TestStr2
+ {
+ ///
+ /// 备注1
+ ///
+ [StringLength(200)]
+ public string DefualtLength { get; set; }
+
+ ///
+ /// 备注1
+ ///
+ [MaxLength]
+ public string MaxLength { get; set; }
+
+ ///
+ /// 备注3
+ ///
+ [StringLength(400)]
+ public string DefineLength { get; set; }
}
#endregion
@@ -220,4 +250,21 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL
public string Name { get; set; }
}
#endregion
+
+
+ #region 测试默认值约束
+
+
+ public class TestStrDefaultValue : BaseFullAuditEntity
+ {
+ //手动不给默认值
+ public string Value1 { get; set; }
+
+ //手动给默认值
+ public string Value2 { get; set; } = string.Empty;
+
+ //dbfirst 默认生成方式 项目开启了enable
+ public string Value3 { get; set; } = null!;
+ }
+ #endregion
}