Skip to content

Commit

Permalink
Stop prefixing check constraints.
Browse files Browse the repository at this point in the history
Fixes #27059
  • Loading branch information
AndriySvyryd committed Jan 7, 2022
1 parent 5f90495 commit 72fca6c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/EFCore.Relational/Metadata/IReadOnlyCheckConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ string GetDefaultName(in StoreObjectIdentifier storeObject)
{
var prefix = $"CK_{storeObject.Name}_";
return Uniquifier.Truncate(
ModelName.StartsWith(prefix, StringComparison.Ordinal)
!(AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue27059", out var enabled) && enabled)
|| ModelName.StartsWith(prefix, StringComparison.Ordinal)
? ModelName
: prefix + ModelName,
EntityType.Model.GetMaxIdentifierLength());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ public virtual void CheckConstraint_is_stored_in_snapshot_as_fluent_api()
builder =>
{
builder.Entity<EntityWithTwoProperties>()
.HasCheckConstraint("CK_Customer_AlternateId", "AlternateId > Id", ck => ck.HasName("CK_Customer_AlternateId"));
.HasCheckConstraint("AlternateId", "AlternateId > Id", ck => ck.HasName("CK_Customer_AlternateId"));
builder.Ignore<EntityWithOneProperty>();
},
AddBoilerPlate(
Expand All @@ -732,7 +732,7 @@ public virtual void CheckConstraint_is_stored_in_snapshot_as_fluent_api()
b.ToTable(""EntityWithTwoProperties"");
b.HasCheckConstraint(""CK_Customer_AlternateId"", ""AlternateId > Id"", c => c.HasName(""CK_Customer_AlternateId""));
b.HasCheckConstraint(""AlternateId"", ""AlternateId > Id"", c => c.HasName(""CK_Customer_AlternateId""));
});"),
o =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ await Test(
e.HasKey("CustomId");
e.HasAlternateKey("SSN");
e.HasCheckConstraint("EmployerId", $"{DelimitIdentifier("EmployerId")} > 0");
e.HasCheckConstraint("CK_People_EmployerId", $"{DelimitIdentifier("EmployerId")} > 0");
e.HasOne("Employers").WithMany("People").HasForeignKey("EmployerId");
e.HasComment("Table comment");
Expand Down Expand Up @@ -641,7 +641,7 @@ public virtual Task Add_column_with_check_constraint()
"People", e =>
{
e.Property<int>("DriverLicense");
e.HasCheckConstraint("Foo", $"{DelimitIdentifier("DriverLicense")} > 0");
e.HasCheckConstraint("CK_People_Foo", $"{DelimitIdentifier("DriverLicense")} > 0");
}),
model =>
{
Expand Down Expand Up @@ -1307,7 +1307,7 @@ public virtual Task Add_check_constraint_with_name()
e.Property<int>("DriverLicense");
}),
builder => { },
builder => builder.Entity("People").HasCheckConstraint("Foo", $"{DelimitIdentifier("DriverLicense")} > 0"),
builder => builder.Entity("People").HasCheckConstraint("CK_People_Foo", $"{DelimitIdentifier("DriverLicense")} > 0"),
model =>
{
// TODO: no scaffolding support for check constraints, https://github.com/aspnet/EntityFrameworkCore/issues/15408
Expand All @@ -1322,8 +1322,8 @@ public virtual Task Alter_check_constraint()
e.Property<int>("Id");
e.Property<int>("DriverLicense");
}),
builder => builder.Entity("People").HasCheckConstraint("Foo", $"{DelimitIdentifier("DriverLicense")} > 0"),
builder => builder.Entity("People").HasCheckConstraint("Foo", $"{DelimitIdentifier("DriverLicense")} > 1"),
builder => builder.Entity("People").HasCheckConstraint("CK_People_Foo", $"{DelimitIdentifier("DriverLicense")} > 0"),
builder => builder.Entity("People").HasCheckConstraint("CK_People_Foo", $"{DelimitIdentifier("DriverLicense")} > 1"),
model =>
{
// TODO: no scaffolding support for check constraints, https://github.com/aspnet/EntityFrameworkCore/issues/15408
Expand All @@ -1338,7 +1338,7 @@ public virtual Task Drop_check_constraint()
e.Property<int>("Id");
e.Property<int>("DriverLicense");
}),
builder => builder.Entity("People").HasCheckConstraint("Foo", $"{DelimitIdentifier("DriverLicense")} > 0"),
builder => builder.Entity("People").HasCheckConstraint("CK_People_Foo", $"{DelimitIdentifier("DriverLicense")} > 0"),
builder => { },
model =>
{
Expand Down

0 comments on commit 72fca6c

Please sign in to comment.