SqlField RegisterCteField(ISqlExpression baseExpression, [NotNull] ISqlExpression expression, int index, string alias) { if (expression == null) { throw new ArgumentNullException(nameof(expression)); } var cteField = _cte.RegisterFieldMapping(baseExpression, expression, index, () => { var f = QueryHelper.GetUnderlyingField(baseExpression ?? expression); var newField = f == null ? new SqlField { SystemType = expression.SystemType, CanBeNull = expression.CanBeNull, Name = alias } : new SqlField(f); newField.PhysicalName = newField.Name; return(newField); }); if (!SqlTable.Fields.TryGetValue(cteField.Name, out var field)) { field = new SqlField(cteField); SqlTable.Add(field); } return(field); }