I understand that GO
is not actual valid SQL and instead a keyword used by SSMS to separate scripts into batches. What I don't understand is why it still works in Migrations.
I have several scripts with GO
in them, and run them as part of EF Core Migrations, which hasn't given me any trouble:
migrationBuilder.Sql(File.ReadAllText("ScriptContainingGO.sql"));
I recently made a change to a tool to run the scripts outside of Migrations on the Database context:
dbContext.Database.ExecuteSqlCommand(File.ReadAllText("ScriptContainingGO.sql"));
This results in the error:
System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near 'GO'.
Which I understand, but why it does work if part of a Migration?
User contributions licensed under CC BY-SA 3.0