public override SelectExpression Select(IEntityType entityType)
        {
            if (entityType.HasTemporalTable())
            {
                var _TemporalTableExpression = new TemporalTableExpression(
                    entityType.GetTableName(),
                    entityType.GetSchema(),
                    entityType.GetTableName().ToLower().Substring(0, 1));

                return(base.Select(entityType, _TemporalTableExpression));
            }

            return(base.Select(entityType));
        }
コード例 #2
0
        protected virtual Expression VisitTemporalTable(TemporalTableExpression tableExpression)
        {
            Sql.Append(SqlGenerationHelper.DelimitIdentifier(tableExpression.Name, tableExpression.Schema));


            switch (tableExpression.TemporalQueryType)
            {
            case TemporalQueryType.None:
                break;

            case TemporalQueryType.AsOf:
            {
                var _AsOfDate = tableExpression.AsOfDate.Name;

                Sql.Append($" FOR SYSTEM_TIME AS OF @{_AsOfDate}");

                if (!CommandBuilder.Parameters.Any(x => x.InvariantName == tableExpression.AsOfDate.Name))
                {
                    CommandBuilder.AddParameter(tableExpression.AsOfDate.Name, _AsOfDate);
                }

                break;
            }

            case TemporalQueryType.FromTo:
            {
                var _StartDate = tableExpression.StartDate.Name;
                var _EndDate   = tableExpression.EndDate.Name;

                Sql.Append($" FOR SYSTEM_TIME FROM @{_StartDate} TO @{_EndDate}");

                if (!CommandBuilder.Parameters.Any(x => x.InvariantName == _StartDate))
                {
                    CommandBuilder.AddParameter(_StartDate, _StartDate);
                }

                if (!CommandBuilder.Parameters.Any(x => x.InvariantName == _EndDate))
                {
                    CommandBuilder.AddParameter(_EndDate, _EndDate);
                }

                break;
            }

            case TemporalQueryType.BetweenAnd:
            {
                var _StartDate = tableExpression.StartDate.Name;
                var _EndDate   = tableExpression.EndDate.Name;

                Sql.Append($" FOR SYSTEM_TIME BETWEEN @{_StartDate} AND @{_EndDate}");

                if (!CommandBuilder.Parameters.Any(x => x.InvariantName == _StartDate))
                {
                    CommandBuilder.AddParameter(_StartDate, _StartDate);
                }

                if (!CommandBuilder.Parameters.Any(x => x.InvariantName == _EndDate))
                {
                    CommandBuilder.AddParameter(_EndDate, _EndDate);
                }

                break;
            }

            case TemporalQueryType.ContainedIn:
            {
                var _StartDate = tableExpression.StartDate.Name;
                var _EndDate   = tableExpression.EndDate.Name;

                Sql.Append($" FOR SYSTEM_TIME CONTAINED IN(@{_StartDate}, @{_EndDate})");

                if (!CommandBuilder.Parameters.Any(x => x.InvariantName == _StartDate))
                {
                    CommandBuilder.AddParameter(_StartDate, _StartDate);
                }

                if (!CommandBuilder.Parameters.Any(x => x.InvariantName == _EndDate))
                {
                    CommandBuilder.AddParameter(_EndDate, _EndDate);
                }

                break;
            }

            case TemporalQueryType.All:
            {
                Sql.Append(" FOR SYSTEM_TIME ALL");
                break;
            }

            default:
                break;
            }

            Sql
            .Append(AliasSeparator)
            .Append(SqlGenerationHelper.DelimitIdentifier(tableExpression.Alias));

            return(tableExpression);
        }