diff --git a/src/CSharp/EasyMicroservices.ContentsMicroservice.Database/Database/Contexts/ContentContext.cs b/src/CSharp/EasyMicroservices.ContentsMicroservice.Database/Database/Contexts/ContentContext.cs index 2a31c4a..ca193e7 100644 --- a/src/CSharp/EasyMicroservices.ContentsMicroservice.Database/Database/Contexts/ContentContext.cs +++ b/src/CSharp/EasyMicroservices.ContentsMicroservice.Database/Database/Contexts/ContentContext.cs @@ -23,7 +23,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(model => { model.HasKey(x => x.Id); + model.HasIndex(x => x.Key).IsUnique(); + model.Property(x => x.Key).UseCollation("SQL_Latin1_General_CP1_CS_AS"); }); + modelBuilder.Entity(model => { model.HasKey(x => x.Id); diff --git a/src/CSharp/EasyMicroservices.ContentsMicroservice.Database/Migrations/20231019201444_FixCaseSensitive_Key_CategoryEntity.Designer.cs b/src/CSharp/EasyMicroservices.ContentsMicroservice.Database/Migrations/20231019201444_FixCaseSensitive_Key_CategoryEntity.Designer.cs new file mode 100644 index 0000000..c6970ed --- /dev/null +++ b/src/CSharp/EasyMicroservices.ContentsMicroservice.Database/Migrations/20231019201444_FixCaseSensitive_Key_CategoryEntity.Designer.cs @@ -0,0 +1,220 @@ +// +using System; +using EasyMicroservices.ContentsMicroservice.Database.Contexts; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EasyMicroservices.ContentsMicroservice.Migrations +{ + [DbContext(typeof(ContentContext))] + [Migration("20231019201444_FixCaseSensitive_Key_CategoryEntity")] + partial class FixCaseSensitive_Key_CategoryEntity + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("EasyMicroservices.ContentsMicroservice.Database.Entities.CategoryEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDateTime") + .HasColumnType("datetime2"); + + b.Property("DeletedDateTime") + .HasColumnType("datetime2"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Key") + .HasColumnType("nvarchar(450)") + .UseCollation("SQL_Latin1_General_CP1_CS_AS"); + + b.Property("ModificationDateTime") + .HasColumnType("datetime2"); + + b.Property("UniqueIdentity") + .HasColumnType("nvarchar(450)") + .UseCollation("SQL_Latin1_General_CP1_CS_AS"); + + b.HasKey("Id"); + + b.HasIndex("CreationDateTime"); + + b.HasIndex("DeletedDateTime"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("Key") + .IsUnique() + .HasFilter("[Key] IS NOT NULL"); + + b.HasIndex("ModificationDateTime"); + + b.HasIndex("UniqueIdentity"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("EasyMicroservices.ContentsMicroservice.Database.Entities.ContentEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("bigint"); + + b.Property("CreationDateTime") + .HasColumnType("datetime2"); + + b.Property("Data") + .HasColumnType("nvarchar(max)"); + + b.Property("DeletedDateTime") + .HasColumnType("datetime2"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LanguageId") + .HasColumnType("bigint"); + + b.Property("ModificationDateTime") + .HasColumnType("datetime2"); + + b.Property("UniqueIdentity") + .HasColumnType("nvarchar(450)") + .UseCollation("SQL_Latin1_General_CP1_CS_AS"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("CreationDateTime"); + + b.HasIndex("DeletedDateTime"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("LanguageId"); + + b.HasIndex("ModificationDateTime"); + + b.HasIndex("UniqueIdentity"); + + b.ToTable("Contents"); + }); + + modelBuilder.Entity("EasyMicroservices.ContentsMicroservice.Database.Entities.LanguageEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDateTime") + .HasColumnType("datetime2"); + + b.Property("DeletedDateTime") + .HasColumnType("datetime2"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("ModificationDateTime") + .HasColumnType("datetime2"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("UniqueIdentity") + .HasColumnType("nvarchar(450)") + .UseCollation("SQL_Latin1_General_CP1_CS_AS"); + + b.HasKey("Id"); + + b.HasIndex("CreationDateTime"); + + b.HasIndex("DeletedDateTime"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ModificationDateTime"); + + b.HasIndex("Name") + .IsUnique() + .HasFilter("[Name] IS NOT NULL"); + + b.HasIndex("UniqueIdentity"); + + b.ToTable("Languages"); + + b.HasData( + new + { + Id = 1L, + CreationDateTime = new DateTime(2023, 10, 19, 23, 44, 44, 432, DateTimeKind.Local).AddTicks(6986), + IsDeleted = false, + Name = "fa-IR" + }, + new + { + Id = 2L, + CreationDateTime = new DateTime(2023, 10, 19, 23, 44, 44, 432, DateTimeKind.Local).AddTicks(6999), + IsDeleted = false, + Name = "en-US" + }); + }); + + modelBuilder.Entity("EasyMicroservices.ContentsMicroservice.Database.Entities.ContentEntity", b => + { + b.HasOne("EasyMicroservices.ContentsMicroservice.Database.Entities.CategoryEntity", "Category") + .WithMany("Contents") + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EasyMicroservices.ContentsMicroservice.Database.Entities.LanguageEntity", "Language") + .WithMany("Contents") + .HasForeignKey("LanguageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("Language"); + }); + + modelBuilder.Entity("EasyMicroservices.ContentsMicroservice.Database.Entities.CategoryEntity", b => + { + b.Navigation("Contents"); + }); + + modelBuilder.Entity("EasyMicroservices.ContentsMicroservice.Database.Entities.LanguageEntity", b => + { + b.Navigation("Contents"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/CSharp/EasyMicroservices.ContentsMicroservice.Database/Migrations/20231019201444_FixCaseSensitive_Key_CategoryEntity.cs b/src/CSharp/EasyMicroservices.ContentsMicroservice.Database/Migrations/20231019201444_FixCaseSensitive_Key_CategoryEntity.cs new file mode 100644 index 0000000..077c5c9 --- /dev/null +++ b/src/CSharp/EasyMicroservices.ContentsMicroservice.Database/Migrations/20231019201444_FixCaseSensitive_Key_CategoryEntity.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EasyMicroservices.ContentsMicroservice.Migrations +{ + /// + public partial class FixCaseSensitive_Key_CategoryEntity : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Key", + table: "Categories", + type: "nvarchar(450)", + nullable: true, + collation: "SQL_Latin1_General_CP1_CS_AS", + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.UpdateData( + table: "Languages", + keyColumn: "Id", + keyValue: 1L, + column: "CreationDateTime", + value: new DateTime(2023, 10, 19, 23, 44, 44, 432, DateTimeKind.Local).AddTicks(6986)); + + migrationBuilder.UpdateData( + table: "Languages", + keyColumn: "Id", + keyValue: 2L, + column: "CreationDateTime", + value: new DateTime(2023, 10, 19, 23, 44, 44, 432, DateTimeKind.Local).AddTicks(6999)); + + migrationBuilder.CreateIndex( + name: "IX_Categories_Key", + table: "Categories", + column: "Key", + unique: true, + filter: "[Key] IS NOT NULL"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_Categories_Key", + table: "Categories"); + + migrationBuilder.AlterColumn( + name: "Key", + table: "Categories", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(450)", + oldNullable: true, + oldCollation: "SQL_Latin1_General_CP1_CS_AS"); + + migrationBuilder.UpdateData( + table: "Languages", + keyColumn: "Id", + keyValue: 1L, + column: "CreationDateTime", + value: new DateTime(2023, 8, 31, 17, 37, 24, 623, DateTimeKind.Local).AddTicks(8580)); + + migrationBuilder.UpdateData( + table: "Languages", + keyColumn: "Id", + keyValue: 2L, + column: "CreationDateTime", + value: new DateTime(2023, 8, 31, 17, 37, 24, 623, DateTimeKind.Local).AddTicks(8591)); + } + } +} diff --git a/src/CSharp/EasyMicroservices.ContentsMicroservice.Database/Migrations/ContentContextModelSnapshot.cs b/src/CSharp/EasyMicroservices.ContentsMicroservice.Database/Migrations/ContentContextModelSnapshot.cs index 8e4c925..e426d21 100644 --- a/src/CSharp/EasyMicroservices.ContentsMicroservice.Database/Migrations/ContentContextModelSnapshot.cs +++ b/src/CSharp/EasyMicroservices.ContentsMicroservice.Database/Migrations/ContentContextModelSnapshot.cs @@ -17,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.10") + .HasAnnotation("ProductVersion", "7.0.11") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); @@ -40,7 +40,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("bit"); b.Property("Key") - .HasColumnType("nvarchar(max)"); + .HasColumnType("nvarchar(450)") + .UseCollation("SQL_Latin1_General_CP1_CS_AS"); b.Property("ModificationDateTime") .HasColumnType("datetime2"); @@ -57,6 +58,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("IsDeleted"); + b.HasIndex("Key") + .IsUnique() + .HasFilter("[Key] IS NOT NULL"); + b.HasIndex("ModificationDateTime"); b.HasIndex("UniqueIdentity"); @@ -165,14 +170,14 @@ protected override void BuildModel(ModelBuilder modelBuilder) new { Id = 1L, - CreationDateTime = new DateTime(2023, 8, 31, 17, 37, 24, 623, DateTimeKind.Local).AddTicks(8580), + CreationDateTime = new DateTime(2023, 10, 19, 23, 44, 44, 432, DateTimeKind.Local).AddTicks(6986), IsDeleted = false, Name = "fa-IR" }, new { Id = 2L, - CreationDateTime = new DateTime(2023, 8, 31, 17, 37, 24, 623, DateTimeKind.Local).AddTicks(8591), + CreationDateTime = new DateTime(2023, 10, 19, 23, 44, 44, 432, DateTimeKind.Local).AddTicks(6999), IsDeleted = false, Name = "en-US" });