Incorrect syntax in the script generated by command "migrations script --idempotent"
Hello,
I have a project with multiple migrations.
One of the migration have multiple procedures like this :
private static string SCRIPT_TableUserSynchronizationRepository_GetFirstPendingUserSynchronizations =
@"CREATE PROCEDURE procedure_GetFirstPendingUserSynchronizations
[...]
END";
When i execute the command line "dotnet ef migrations script" everything work fine !
But when i execute the code generated by the command "dotnet ef migrations script --idempotent" i have several errors !
EF generate this kind of code :
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20171124083142_addStoredProcedures')
BEGIN
CREATE PROCEDURE procedure_GetFirstPendingUserSynchronizations
[...]
END
END;
GO
And the error is "Incorrect syntax near the keyword 'Procedure'".
I have found a workaround by putting the "CREATE PROCEDURE" in "EXE(' [...]'). https://stackoverflow.com/questions/16729520/incorrect-syntax-near-the-keyword-procedure.
I use SQL Server 2016 (localdb)
Is it an EF Core bug ?
It's more-or-less by design. EF Core doesn't know which statements need to be in their own batch or the first statement in a batch, so you're responsible for wrapping them inside EXEC as needed.
Per @bricelam's comment, closing this as by-design.
This is giving me some grief also. My hope was to generate scripts during my build pipeline with --idempotent, then pass it along to different release environments. I won't be able to effectively build in CI/CD if I have to manually edit the output. Understand this is pretty much by design, but at risk of being naive is it harmful if the tooling preemptively wraps everything in EXEC?
See https://github.com/aspnet/EntityFrameworkCore/issues/12911#issuecomment-416699916
Thanks Brice. Looking forward to 3.0.
Best Regards
On Wed, Feb 6, 2019 at 2:41 PM Brice Lambson [email protected] wrote:
See #12911 (comment) https://github.com/aspnet/EntityFrameworkCore/issues/12911#issuecomment-416699916
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/aspnet/EntityFrameworkCore/issues/10726#issuecomment-461159009, or mute the thread https://github.com/notifications/unsubscribe-auth/AKdfK-RlWD4GicVWPw46qvuN50o-V8sUks5vKy_LgaJpZM4Rkfd2 .