Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF Core 6.0 temporal tables - Support specifying precision for PeriodEnd and PeriodStart columns #27228

Closed
Mithras opened this issue Jan 20, 2022 · 1 comment · Fixed by #28651
Assignees
Labels
area-model-building area-temporal-tables closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Milestone

Comments

@Mithras
Copy link

Mithras commented Jan 20, 2022

What problem are you trying to solve?

Right now it's not possible to specify precision for PeriodEnd and PeriodStart columns. We already have temporal tables in our DB and we happened to use datetime2(0) instead of just datetime2 for PeriodEnd and PeriodStart columns.

Describe the solution you'd like

builder.ToTable(tableBuilder => tableBuilder.IsTemporal(temporalTableBuilder =>
{
  temporalTableBuilder.HasPeriodStart("MyPeriodStart").HasPrecision(0); // <--- something like this
  temporalTableBuilder.HasPeriodEnd("MyPeriodEnd").HasPrecision(0); // <--- something like this
  temporalTableBuilder.UseHistoryTable("MyHistory");
}));
@ajcvickers
Copy link
Contributor

Note for triage. While the model builder does allow configuration of the shadow properties with:

modelBuilder.Entity<Employee>().Property("MyPeriodStart").HasPrecision(0);

Or

modelBuilder.Entity<Employee>().Property("MyPeriodStart").HasColumnType("datetime2(0)");

The model validator requires that the type be exactly "datetime2":

const string expectedPeriodColumnName = "datetime2";
if (periodProperty.GetColumnType() != expectedPeriodColumnName)
{
    throw new InvalidOperationException(
        SqlServerStrings.TemporalPeriodPropertyMustBeMappedToDatetime2(
            temporalEntityType.DisplayName(), periodProperty.Name, expectedPeriodColumnName));
}

@maumar maumar self-assigned this Jan 24, 2022
@maumar maumar added this to the 7.0.0 milestone Jan 25, 2022
maumar added a commit that referenced this issue Aug 10, 2022
…ision for PeriodEnd and PeriodStart columns

Added HasPrecision builder methods for temporal period columns and fixed validation so that it can recognize custom precision.

Fixes #27228
@maumar maumar added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 10, 2022
@maumar maumar closed this as completed in 41a82fa Aug 11, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0, 7.0.0-rc1 Aug 12, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-rc1, 7.0.0 Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building area-temporal-tables closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Projects
None yet
3 participants