-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Temporal table support for owned and table splitting scenarios #26935
Conversation
src/EFCore.SqlServer/Query/Internal/SqlServerQueryableMethodTranslatingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs
Outdated
Show resolved
Hide resolved
c173a6b
to
421ec8c
Compare
src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs
Outdated
Show resolved
Hide resolved
421ec8c
to
58f7223
Compare
src/EFCore.Relational/Metadata/Builders/OwnedNavigationTableBuilder.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Metadata/Builders/OwnedNavigationTableBuilder.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Query/SqlExpressions/ISqlExpressionAnnotatable.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Metadata/Builders/OwnedNavigationTemporalTableBuilder.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Internal/SqlServerSqlExpressionAnnotationNames.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Relational.Tests/ModelBuilding/RelationalModelBuilderGenericTestBase.cs
Show resolved
Hide resolved
d861a8f
to
de6c2e2
Compare
de6c2e2
to
67bcbe1
Compare
src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Internal/SqlServerQueryableMethodTranslatingExpressionVisitor.cs
Show resolved
Hide resolved
f5c0ad2
to
2dec3c8
Compare
2dec3c8
to
c04b67c
Compare
new (hopefully final) version is up @AndriySvyryd |
src/EFCore.SqlServer/Metadata/Conventions/SqlServerConventionSetBuilder.cs
Show resolved
Hide resolved
It's best to keep the commits separate once the PR has been reviewed. |
src/EFCore.SqlServer/Metadata/Builders/OwnedNavigationTemporalTableBuilder.cs
Outdated
Show resolved
Hide resolved
12cc146
to
c0b43a9
Compare
Fix to #26858 - Query: improve TableExpressionBase extensibility by adding annotations Fix to #26469 - Query: enable temporal tables for table splitting scenarios Fix to #26451 - Temporal Table: Owned Entities support? Added annotation infra for TableExpressionBase and annotations for temporal table information. Removed (now unnecessary) temporal specific table expressions. Also added temporal table support for owned typed and table splitting in general using the annotations to store the temporal information (no need for provider specific logic in places where we didn't have good extensibility) For table splitting, every entity must explicitly define period start/end columns. They all need to be the same, but if not explicitly provided we try to uniquefy them. We should fix this so that you only need to specify it in one place but it's currently hard to do (hopefully convention layering will make it easier) Fixes #26858 Fixes #26469 Fixes #26451
c0b43a9
to
1ca6380
Compare
Hi @maumar - do you happen to know if this fix will be made available in a minor EF Core 6 update at some point, or will it not be available until EF Core 7 is released? Was excited to see support for temporal tables with EF Core 6, however, then realized we could not use the functionality since we are using Owned Entities in some cases. Looking forward to your reply! |
@spallister Follow #27380 for the answer to your question |
Oh great - Thanks, @AndriySvyryd! |
when i have multiple owned types i get this error
Here is my code builder.Entity<Merchant>().ToTable((o) =>
{
o.IsTemporal(t =>
{
t.HasPeriodEnd(PeriodEnd);
t.HasPeriodStart(PeriodStart);
});
});
builder.Entity<Merchant>().OwnsOne(o => o.CommerialRegistration, x => ConfigureTemporal(x));
builder.Entity<Merchant>().OwnsOne(o => o.NationalId, x => ConfigureTemporal(x));
builder.Entity<Merchant>().OwnsOne(o => o.BankInfo, x => ConfigureTemporal(x));
builder.Entity<Merchant>().OwnsOne(o => o.Location, x => ConfigureTemporal(x)); void ConfigureTemporal<TEntity, TRelatedEntity>(OwnedNavigationBuilder<TEntity, TRelatedEntity> builder) where TEntity : class where TRelatedEntity : class
{
builder.WithOwner();
builder.ToTable(t => t.IsTemporal(t =>
{
t.HasPeriodEnd(PeriodEnd);
t.HasPeriodStart(PeriodStart);
}));
} |
it was solved by |
@maumar modelBuilder.Entity<Customer>(customer =>
{
customer.ToTable("Customers", t => t.IsTemporal(x =>
{
x.UseHistoryTable("CustomersHistory");
x.HasPeriodStart("PeriodStart");
x.HasPeriodEnd("PeriodEnd");
}));
customer.Property<DateTime>("PeriodStart").HasColumnName("PeriodStart");
customer.Property<DateTime>("PeriodEnd").HasColumnName("PeriodEnd");
customer.OwnsOne(x => x.CustomerDetail, customerDetail =>
{
customerDetail.ToTable("Customers", t => t.IsTemporal(x =>
{
x.UseHistoryTable("CustomersHistory");
x.HasPeriodStart("PeriodStart");
x.HasPeriodEnd("PeriodEnd");
}));
customerDetail.Property<DateTime>("PeriodStart").HasColumnName("PeriodStart");
customerDetail.Property<DateTime>("PeriodEnd").HasColumnName("PeriodEnd");
});
}); |
Fix to #26858 - Query: improve TableExpressionBase extensibility by adding annotations
Fix to #26469 - Query: enable temporal tables for table splitting scenarios
Fix to #26451 - Temporal Table: Owned Entities support?
Added annotation infra for TableExpressionBase and annotations for temporal table information. Removed (now unnecessary) temporal specific table expressions.
Also added temporal table support for owned typed and table splitting in general using the annotations to store the temporal information (no need for provider specific logic in places where we didn't have good extensibility)
For table splitting, every entity must explicitly define period start/end columns. They all need to be the same, but if not explicitly provided we try to uniquefy them. We should fix this so that you only need to specify it in one place but it's currently hard to do (hopefully convention layering will make it easier)
Fixes #26858
Fixes #26469
Fixes #26451