EF Migration, text output to Nuget console

When I start migrations to create a database through the package manager console. Is there a way to output text from the Seed method to the NuGet console?

Just create a command:

Update-Database -StartupProjectName "Data" -Verbose 
+7
source share
3 answers

I don't think you can output it directly, but you can use the trace and debug commands and attach another VS instance to view the output.

From this question: Where can I find the console or debug the output from the code executed in the package manager window?

+2
source

You can execute the SQL PRINT command in the Up() or Down() methods for each individual migration.

 base.Sql("PRINT 'I heart kittens';"); 

This will cause "I heart kittens" to appear in the package manager console window in highlighted yellow text during the "update-database" process.

+2
source

Team

 Update-Database -Verbose 

print in the console sql code for migration, but another way:

 Update-Database -Script 

which open another file in Visual Studio with sql code.

This is the only way to get sql migration code. You cannot get sql migration code in debugging because the migration is performed as a power shell and because it does not start the project.

Editing:

You cannot migrate or make your debut because the migration is executed as a shell command.

You can get Entity Framework> Migration source code at entityframework.codeplex.com

+1
source

All Articles