protected virtual Expression VisitAsOfTable(AsOfTableExpression tableExpression) { // This method was modeled on "SqlServerQuerySqlGenerator.VisitTable". // Where we deviate, is after printing the table name, we check if temporal constraints // need to be applied. Sql.Append(_sqlGenerationHelper.DelimitIdentifier(tableExpression.Name, tableExpression.Schema)); if (tableExpression.AsOfDate != null) { var name = TEMPORAL_PARAMETER_PREFIX + tableExpression.AsOfDate.Name; Sql.Append($" FOR SYSTEM_TIME AS OF @{name}"); //2020-02-28T11:00:00 if (!_commandbuilder.Parameters.Any(x => x.InvariantName == tableExpression.AsOfDate.Name)) { _commandbuilder.AddParameter(tableExpression.AsOfDate.Name, name); } } Sql .Append(AliasSeparator) .Append(_sqlGenerationHelper.DelimitIdentifier(tableExpression.Alias)); return(tableExpression); }
protected virtual Expression VisitAsOfTable(AsOfTableExpression tableExpression) { Sql.Append(_sqlGenerationHelper.DelimitIdentifier(tableExpression.Name, tableExpression.Schema)); if (tableExpression.DateParameter != null) { var name = "__ef_temporal" + tableExpression.DateParameter.Name; Sql.Append($" FOR SYSTEM_TIME AS OF @{name}"); //2020-02-28T11:00:00 if (!_commandbuilder.Parameters.Any(x => x.InvariantName == tableExpression.DateParameter.Name)) { _commandbuilder.AddParameter(tableExpression.DateParameter.Name, name); } } Sql .Append(AliasSeparator) .Append(_sqlGenerationHelper.DelimitIdentifier(tableExpression.Alias)); return(tableExpression); }
public override SelectExpression Select(IEntityType entityType) { if (entityType.FindAnnotation(SqlServerEntityTypeBuilderExtensions.ANNOTATION_TEMPORAL) != null) { var asOfTableExpression = new AsOfTableExpression( entityType.GetTableName(), entityType.GetSchema(), entityType.GetTableName().ToLower().Substring(0, 1)); var selectContructor = typeof(SelectExpression).GetConstructor(BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, new Type[] { typeof(IEntityType), typeof(TableExpressionBase) }, null); var select = (SelectExpression)selectContructor.Invoke(new object[] { entityType, asOfTableExpression }); var privateInitializer = typeof(SqlExpressionFactory).GetMethod("AddConditions", BindingFlags.NonPublic | BindingFlags.Instance); privateInitializer.Invoke(this, new object[] { select, entityType, null, null }); return(select); } return(base.Select(entityType)); }