Skip to content

Commit

Permalink
Fix casesensitive key
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Oct 19, 2023
1 parent a9cda63 commit 98bb8af
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<CategoryEntity>(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<ContentEntity>(model =>
{
model.HasKey(x => x.Id);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace EasyMicroservices.ContentsMicroservice.Migrations
{
/// <inheritdoc />
public partial class FixCaseSensitive_Key_CategoryEntity : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
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");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_Categories_Key",
table: "Categories");

migrationBuilder.AlterColumn<string>(
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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -40,7 +40,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("bit");

b.Property<string>("Key")
.HasColumnType("nvarchar(max)");
.HasColumnType("nvarchar(450)")
.UseCollation("SQL_Latin1_General_CP1_CS_AS");

b.Property<DateTime?>("ModificationDateTime")
.HasColumnType("datetime2");
Expand All @@ -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");
Expand Down Expand Up @@ -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"
});
Expand Down

0 comments on commit 98bb8af

Please sign in to comment.