Hi,
I just discovered that, in my database, on 3 temporal tables, the meaning of the PeriodStart and PeriodEnd column has been kind of swapped after renaming them (to be compliant with our naming convention).
As a result, dates in the new PeriodStart-like column are greater than the dates in the PeriodEnd one.
Repro steps:
Having this entity model:
public class Contact : IEntity
{
/// <inheritdoc />
public Guid Id { get; set; }
}
Having this in DbContext:
modelBuilder.Entity<Contact>(
entity =>
{
entity.ToTable(
builder =>
{
builder.IsTemporal();
});
entity.HasKey(c => c.Id).HasName("ConId");
});
Generates the following migration Up():
migrationBuilder.AlterTable(
name: "Contacts")
.Annotation("SqlServer:IsTemporal", true)
.Annotation("SqlServer:TemporalHistoryTableName", "ContactsHistory")
.Annotation("SqlServer:TemporalHistoryTableSchema", null)
.Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd")
.Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart");
migrationBuilder.AddColumn<DateTime>(
name: "PeriodEnd",
table: "Contacts",
type: "datetime2",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified))
.Annotation("SqlServer:IsTemporal", true)
.Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd")
.Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart");
migrationBuilder.AddColumn<DateTime>(
name: "PeriodStart",
table: "Contacts",
type: "datetime2",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified))
.Annotation("SqlServer:IsTemporal", true)
.Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd")
.Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart");
Then, if we are to rename the columns to be compliant with the Con prefix trigram, we add this to the DbContext:
modelBuilder.Entity<Contact>(
entity =>
{
entity.ToTable(
builder =>
{
builder.IsTemporal(
tableBuilder =>
{
tableBuilder.HasPeriodStart("ConValidFrom");
tableBuilder.HasPeriodEnd("ConValidTo");
});
});
entity.HasKey(c => c.Id).HasName("ConId");
});
And this is the resulting migration Up() generated method:
migrationBuilder.RenameColumn(
name: "PeriodStart",
table: "Contacts",
newName: "ConValidTo");
migrationBuilder.RenameColumn(
name: "PeriodEnd",
table: "Contacts",
newName: "ConValidFrom");
migrationBuilder.AlterTable(
name: "Contacts")
.Annotation("SqlServer:IsTemporal", true)
.Annotation("SqlServer:TemporalHistoryTableName", "ContactsHistory")
.Annotation("SqlServer:TemporalHistoryTableSchema", null)
.Annotation("SqlServer:TemporalPeriodEndColumnName", "ConValidTo")
.Annotation("SqlServer:TemporalPeriodStartColumnName", "ConValidFrom")
.OldAnnotation("SqlServer:IsTemporal", true)
.OldAnnotation("SqlServer:TemporalHistoryTableName", "ContactsHistory")
.OldAnnotation("SqlServer:TemporalHistoryTableSchema", null)
.OldAnnotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd")
.OldAnnotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart");
Here, it seems to me that the renaming of the columns kind of "swaps" them, isn't it ?
Thanks.
Include provider and version information
EF Core version: 6.0.5
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Win 11
IDE: Visual Studio 2022 17.3.6
Hi,
I just discovered that, in my database, on 3 temporal tables, the meaning of the
PeriodStartandPeriodEndcolumn has been kind of swapped after renaming them (to be compliant with our naming convention).As a result, dates in the new
PeriodStart-like column are greater than the dates in thePeriodEndone.Repro steps:
Having this entity model:
Having this in
DbContext:Generates the following migration
Up():Then, if we are to rename the columns to be compliant with the
Conprefix trigram, we add this to theDbContext:And this is the resulting migration
Up()generated method:Here, it seems to me that the renaming of the columns kind of "swaps" them, isn't it ?
Thanks.
Include provider and version information
EF Core version: 6.0.5
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Win 11
IDE: Visual Studio 2022 17.3.6