-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Simplify configuration for temporal tables with owned types #29303
Comments
Any idea if this is being considered on coming releases? |
this worked for me:
|
Thanks. Mine was a little more complicated and since These are all things that could be simplified. |
Having encountered this issue, I've use @ajcvickers approach, explained in the initial post and made a generic, reusable method: private static void ConfigureOwnedNavigationProperty<TModel, TDependent>(OwnedNavigationBuilder<TModel, TDependent> ownedNavigationBuilder)
where TModel : class
where TDependent : class
{
ownedNavigationBuilder.ToTable($"{typeof(TModel).Name}s",
tableBuilder =>
{
tableBuilder.IsTemporal();
tableBuilder.Property<DateTime>(PeriodStart).HasColumnName(PeriodStart);
tableBuilder.Property<DateTime>(PeriodEnd).HasColumnName(PeriodEnd);
});
} IMO it makes it easier to use and reuse with e.g. this localized description builder.OwnsOne(product => product.Description, ConfigureOwnedNavigationProperty); The entity itself, must also be registered as temporal with the same period start/stop columns: private static void ConfigureBase<TModel>(EntityTypeBuilder<TModel> builder)
where TModel : BaseModel
{
builder.HasKey(model => model.Id);
builder.ToTable($"{typeof(TModel).Name}s",
tableBuilder =>
{
tableBuilder.IsTemporal();
tableBuilder.Property<DateTime>(PeriodStart).HasColumnName(PeriodStart);
tableBuilder.Property<DateTime>(PeriodEnd).HasColumnName(PeriodEnd);
});
builder.Property(model => model.Id)
.ValueGeneratedOnAdd();
} |
Ideally, of the owning entity type is configured as temporal, then owned entities mapped to the same table should not need additional configuration to make use of the temporal table, with the same
PeriodStart
andPeriodEnd
columns.For example, this configuration should be sufficient:
But throws:
Attempting to fix this:
Results in:
Attempting the set the column name explicit on one or other type doesn't help. So the simplest config that I can come up with that works is:
The text was updated successfully, but these errors were encountered: