Why goes "GO" work inside a Migration, but not with ExecuteSqlCommand?

0

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?

c#
entity-framework-core
entity-framework-core-migrations
asked on Stack Overflow Nov 9, 2018 by Valuator

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0