/// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        protected override Expression VisitExtension(Expression extensionExpression)
        {
            if (extensionExpression is TemporalQueryRootExpression queryRootExpression)
            {
                // sql server model validator will throw if entity is mapped to multiple tables
                var table = queryRootExpression.EntityType.GetTableMappings().Single().Table;
                var temporalTableExpression = queryRootExpression switch
                {
                    TemporalAllQueryRootExpression _ => (TemporalTableExpression) new TemporalAllTableExpression(table),
                    TemporalAsOfQueryRootExpression asOf => new TemporalAsOfTableExpression(table, asOf.PointInTime),
                    TemporalBetweenQueryRootExpression between => new TemporalBetweenTableExpression(table, between.From, between.To),
                    TemporalContainedInQueryRootExpression containedIn => new TemporalContainedInTableExpression(table, containedIn.From, containedIn.To),
                    TemporalFromToQueryRootExpression fromTo => new TemporalFromToTableExpression(table, fromTo.From, fromTo.To),
                    _ => throw new InvalidOperationException(queryRootExpression.Print())
                };

                var selectExpression = RelationalDependencies.SqlExpressionFactory.Select(
                    queryRootExpression.EntityType,
                    temporalTableExpression);

                return(new ShapedQueryExpression(
                           selectExpression,
                           new RelationalEntityShaperExpression(
                               queryRootExpression.EntityType,
                               new ProjectionBindingExpression(
                                   selectExpression,
                                   new ProjectionMember(),
                                   typeof(ValueBuffer)),
                               false)));
            }

            return(base.VisitExtension(extensionExpression));
        }
    }
Пример #2
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        protected override Expression VisitExtension(Expression extensionExpression)
        {
            if (extensionExpression is TemporalAsOfQueryRootExpression ||
                extensionExpression is TemporalRangeQueryRootExpression ||
                extensionExpression is TemporalAllQueryRootExpression)
            {
                var queryRootExpression = (QueryRootExpression)extensionExpression;

                // sql server model validator will throw if entity is mapped to multiple tables
                var table = queryRootExpression.EntityType.GetTableMappings().Single().Table;
                var temporalTableExpression = queryRootExpression switch
                {
                    TemporalRangeQueryRootExpression range => new TemporalTableExpression(
                        table,
                        range.From,
                        range.To,
                        range.TemporalOperationType),
                    TemporalAsOfQueryRootExpression asOf => new TemporalTableExpression(table, asOf.PointInTime),
                    // all
                    _ => new TemporalTableExpression(table),
                };

                var selectExpression = RelationalDependencies.SqlExpressionFactory.Select(
                    queryRootExpression.EntityType,
                    temporalTableExpression);

                return(new ShapedQueryExpression(
                           selectExpression,
                           new RelationalEntityShaperExpression(
                               queryRootExpression.EntityType,
                               new ProjectionBindingExpression(
                                   selectExpression,
                                   new ProjectionMember(),
                                   typeof(ValueBuffer)),
                               false)));
            }

            return(base.VisitExtension(extensionExpression));
        }