Closed senketsu03 closed 10 months ago
I have the same issue.
When applying snake_casing on tables with TPT (with UseTptMappingStrategy()
), table names and PK constaint names are not transformed into snake case.
Not a blocking issue, because I can rewrite table names. But with custom table names, PK names are labeled "PK_my_custom_table_name" (PK is uppercased).
public abstract class Person
{
public int Id { get; set; }
// ...
}
public class Candidate : Person
{
// ...
}
public class Juror : Person
{
// ...
}
EF entity configuration
builder.Entity<Person>().UseTptMappingStrategy();
// nothing for the inherited `Candidate` and `Juror` entities
What is generated
migrationBuilder.CreateTable(
name: "Persons", // !! not in lowercase
schema: "persons",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false),
// ...
},
constraints: table =>
{
table.PrimaryKey("PK_Persons", x => x.id); // !! not in lowercase
});
migrationBuilder.CreateTable(
name: "Candidates", // !! not in lowercase
schema: "persons",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false),
// ...
},
constraints: table =>
{
table.PrimaryKey("PK_Candidates", x => x.id); // !! not in lowercase
table.ForeignKey(
name: "fk_candidates_persons_id",
column: x => x.id,
principalSchema: "persons",
principalTable: "Persons",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Jurors", // !! not in lowercase
schema: "persons",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false),
// ...
},
constraints: table =>
{
table.PrimaryKey("PK_Jurors", x => x.id); // !! not in lowercase
table.ForeignKey(
name: "fk_jurors_persons_id",
column: x => x.id,
principalSchema: "persons",
principalTable: "Persons",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
For other tables in my db context, the pk and table names are correctly snake cased.
Versions
Same issue here :(
Sorry for taking so long to investigate this. I can indeed reproduce the issue and have pushed a fix for 8.0.0, which is about to get released.
On 7.0, this can be worked around by setting the table names explicitly instead of using UseTptMappingStrategy
:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Student>().ToTable("students");
modelBuilder.Entity<Student>().ToTable("honored_students");
modelBuilder.Entity<Student>().UseTptMappingStrategy();
}
Hello, @roji! Thank you for working on this!
I've tested last versions, the 8.0.1
works fine (tables students
and honored_students
are created), but on 8.0.2
there are Students
and honored_students
are created.
@Gigas002 thanks for flagging this, opened #259 to fix for 8.0.3.
Repro code:
This creates two tables:
Students
andHonoredStudents
. Expected them to be namedstudents
andhonored_students
correspondingly. Of course I can force these names, usingTableAttribute
, but that's not the desired behavior