protected override IEnumerable <Command> OnCreate(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context) { if (IsLegacy) { var command = new Command(); command.Append($"DECLARE EXTERNAL FUNCTION {FunctionName.AsSqlIndentifier()}"); var inputs = FunctionArguments .Where(x => x.ArgumentPosition != ReturnArgument) .OrderBy(x => x.ArgumentPosition) .Select(CreateLegacyArgumentDefinition); command.Append($" {string.Join(", ", inputs)}"); command.AppendLine(); var @return = FunctionArguments.First(x => x.ArgumentPosition == ReturnArgument); command.Append($"RETURNS{(ReturnArgument != 0 ? " PARAMETER" : string.Empty)} {CreateLegacyArgumentDefinition(@return)}"); command.AppendLine(); command.Append($"ENTRY_POINT '{SqlHelper.DoubleSingleQuotes(EntryPoint)}' MODULE_NAME '{SqlHelper.DoubleSingleQuotes(ModuleName)}'"); yield return(command); } else { var command = SqlHelper.IsValidExternalEngine(this) ? new Command() : new PSqlCommand(); command.Append("CREATE OR ALTER FUNCTION"); if (PackageName != null) { command.Append($" {PackageName.AsSqlIndentifier()}.{FunctionName.AsSqlIndentifier()}"); } else { command.Append($" {FunctionName.AsSqlIndentifier()}"); } var inputs = FunctionArguments .Where(x => x.ArgumentPosition != ReturnArgument) .OrderBy(x => x.ArgumentPosition) .Select(x => CreateNewArgumentDefinition(x, sourceMetadata, targetMetadata, context)); var @return = FunctionArguments.First(x => x.ArgumentPosition == ReturnArgument); var output = CreateNewArgumentDefinition(@return, sourceMetadata, targetMetadata, context); command.Append($" ({string.Join(", ", inputs)}) RETURNS {output}"); if (DeterministicFlag == DeterministicFlagType.Deterministic) { command.Append(" DETERMINISTIC"); } command.AppendLine(); if (SqlHelper.IsValidExternalEngine(this)) { command.Append($"EXTERNAL NAME '{SqlHelper.DoubleSingleQuotes(EntryPoint)}'"); command.AppendLine(); command.Append($"ENGINE {EngineName.AsSqlIndentifier()}"); } else { if (SqlSecurity != null) { command.Append($"SQL SECURITY {SqlHelper.SqlSecurityString(SqlSecurity)}"); command.AppendLine(); } command.Append("AS"); command.AppendLine(); if (context.EmptyBodiesEnabled) { command.Append("BEGIN"); command.AppendLine(); command.Append("END"); } else { command.Append(FunctionSource); } } yield return(command); } }