I have a few stored procedures that I'd like to be created during a migration step in Entity Framework core 8.0.7.
I added a new migration, and in the Up() method I put this simple script:
var sp = @"CREATE PROCEDURE [dbo].[MyStoredProcedureFromMigration]
AS
BEGIN
SET NOCOUNT ON;
select * from Students where FirstName like '%dummy%'
END";
migrationBuilder.Sql(sp);
In my Azure Devops pipeline, I generate the idempotent migration script with a DotNetCoreCli task:
IF NOT EXISTS (
SELECT * FROM [__EFMigrationsHistory]
WHERE [MigrationId] = N'20240827132758_NameOfMigration'
)
BEGIN
CREATE PROCEDURE [dbo].[MyStoredProcedureFromMigration]
AS
BEGIN
SET NOCOUNT ON;
select * from Students where FirstName like '%dummy%'
END
END;
GO
which returns an error when running from a SqlAzureDacpacDeployment task in the pipeline:
Incorrect syntax near the keyword 'PROCEDURE'.
If I remove the --idempotent argument, the script is valid but then I get errors because some of the tables already exist, as the generated script is no longer idempotent.
How can I generate a valid new migration script that runs without errors when it contains the creation of stored procedures?
I have a few stored procedures that I'd like to be created during a migration step in Entity Framework core 8.0.7. I added a new migration, and in the
Up()
method I put this simple script:In my Azure Devops pipeline, I generate the idempotent migration script with a DotNetCoreCli task:
But EntityFramework then generates this script:
which returns an error when running from a SqlAzureDacpacDeployment task in the pipeline:
If I remove the
--idempotent
argument, the script is valid but then I get errors because some of the tables already exist, as the generated script is no longer idempotent.How can I generate a valid new migration script that runs without errors when it contains the creation of stored procedures?