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

minor cleanup for temporal table feature #25264

Merged
merged 1 commit into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
namespace Microsoft.EntityFrameworkCore
{
/// <summary>
/// Sql Server database specific extension methods for LINQ queries.
/// Sql Server database specific extension methods for LINQ queries rooted in DbSet.
/// </summary>
public static class SqlServerQueryableExtensions
public static class SqlServerDbSetExtensions
{
/// <summary>
/// <para>
Expand Down Expand Up @@ -97,7 +97,7 @@ public static IQueryable<TEntity> TemporalFromTo<TEntity>(
/// <param name="to">Point in time representing the end of the period for which results should be returned.</param>
/// <returns> An <see cref="IQueryable{T}" /> representing the entities present in a given time range.</returns>
public static IQueryable<TEntity> TemporalBetween<TEntity>(
this IQueryable<TEntity> source,
this DbSet<TEntity> source,
DateTime from,
DateTime to)
where TEntity : class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ public virtual void ProcessEntityTypeAnnotationChanged(
{
entityTypeBuilder.HasPeriodEnd(PeriodEndDefaultName);
}

foreach (var skipLevelNavigation in entityTypeBuilder.Metadata.GetSkipNavigations())
{
if (skipLevelNavigation.DeclaringEntityType.IsTemporal()
&& skipLevelNavigation.Inverse is IConventionSkipNavigation inverse
&& inverse.DeclaringEntityType.IsTemporal()
&& skipLevelNavigation.JoinEntityType is IConventionEntityType joinEntityType
&& joinEntityType.HasSharedClrType
&& !joinEntityType.IsTemporal()
&& joinEntityType.GetConfigurationSource() == ConfigurationSource.Convention)
{
joinEntityType.SetIsTemporal(true);
}
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@
namespace Microsoft.EntityFrameworkCore.SqlServer.Query.SqlExpressions
{
/// <summary>
/// Fill in later
/// <para>
/// An expression that represents a temporal table source in a SQL tree.
/// </para>
/// <para>
/// This type is typically used by database providers (and other extensions). It is generally
/// not used in application code.
/// </para>
/// </summary>
public class TemporalTableExpression : TableExpressionBase, ICloneable
{
/// <summary>
/// Fill in later
/// Creates a new instance of the <see cref="TemporalTableExpression" /> class representing temporal 'All' operation.
/// </summary>
/// <param name="table"> A table source. </param>
public TemporalTableExpression(ITableBase table)
: base(table.Name.Substring(0, 1).ToLowerInvariant())
{
Expand All @@ -26,8 +33,10 @@ public TemporalTableExpression(ITableBase table)
}

/// <summary>
/// Fill in later
/// Creates a new instance of the <see cref="TemporalTableExpression" /> class representing temporal 'AsOf' operation.
/// </summary>
/// <param name="table"> A table source. </param>
/// <param name="pointInTime">Point in time. </param>
public TemporalTableExpression(ITableBase table, DateTime pointInTime)
: base(table.Name.Substring(0, 1).ToLowerInvariant())
{
Expand All @@ -38,8 +47,12 @@ public TemporalTableExpression(ITableBase table, DateTime pointInTime)
}

/// <summary>
/// Fill in later
/// Creates a new instance of the <see cref="TemporalTableExpression" /> class representing temporal range operation.
/// </summary>
/// <param name="table"> A table source. </param>
/// <param name="from">Start of the time range.</param>
/// <param name="to">End of the time range.</param>
/// <param name="temporalOperationType">Temporal operation type.</param>
public TemporalTableExpression(ITableBase table, DateTime from, DateTime to, TemporalOperationType temporalOperationType)
: base(table.Name.Substring(0, 1).ToLowerInvariant())
{
Expand Down Expand Up @@ -69,32 +82,32 @@ private TemporalTableExpression(
}

/// <summary>
/// Fill in later
/// Table schema.
/// </summary>
public virtual string? Schema { get; }

/// <summary>
/// Fill in later
/// Table name.
/// </summary>
public virtual string Name { get; }

/// <summary>
/// Fill in later
/// Point in time for the temporal 'AsOf' operation.
/// </summary>
public virtual DateTime? PointInTime { get; }

/// <summary>
/// Fill in later
/// Start date for the temporal range operation.
/// </summary>
public virtual DateTime? From { get; }

/// <summary>
/// Fill in later
/// End date for the temporal range operation.
/// </summary>
public virtual DateTime? To { get; }

/// <summary>
/// Fill in later
/// Temporal operation type.
/// </summary>
public virtual TemporalOperationType TemporalOperationType { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private static readonly MethodInfo _setMethodInfo
= typeof(ISetSource).GetMethod(nameof(ISetSource.Set));

private static readonly MethodInfo _asOfMethodInfo
= typeof(SqlServerQueryableExtensions).GetMethod(nameof(SqlServerQueryableExtensions.TemporalAsOf));
= typeof(SqlServerDbSetExtensions).GetMethod(nameof(SqlServerDbSetExtensions.TemporalAsOf));

private readonly DateTime _pointInTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,26 @@ public virtual void Switching_from_temporal_to_non_temporal_default_settings()
Assert.Equal(3, entity.GetProperties().Count());
}

[ConditionalFact]
public virtual void Implicit_many_to_many_converted_from_non_temporal_to_temporal()
{
var modelBuilder = CreateModelBuilder();
var model = modelBuilder.Model;

modelBuilder.Entity<ImplicitManyToManyA>();
modelBuilder.Entity<ImplicitManyToManyB>();

modelBuilder.Entity<ImplicitManyToManyA>().ToTable(tb => tb.IsTemporal());
modelBuilder.Entity<ImplicitManyToManyB>().ToTable(tb => tb.IsTemporal());

modelBuilder.FinalizeModel();

var entity = model.FindEntityType(typeof(ImplicitManyToManyA));
var joinEntity = entity.GetSkipNavigations().Single().JoinEntityType;

Assert.True(joinEntity.IsTemporal());
}

protected override TestModelBuilder CreateModelBuilder(Action<ModelConfigurationBuilder> configure = null)
=> CreateTestModelBuilder(SqlServerTestHelpers.Instance, configure);
}
Expand Down