How to use EF code first migration to generate scripts from powershell

entity-framework-6

Question

I have a need to email our DBA when a deployment, that utilizes EF6 code-based migrations, goes out. I am able to use the migrate.exe tool with the verbose flag, through powershell, to get the scripts but each command is truncated after 10222 characters. This usually only effects the model hash for the migrationHistory. Does anyone know of a way to generate the full sql script for EF6 migrations through Powershell

thanks T

1
1
7/8/2016 6:46:10 PM

Popular Answer

Figured out that migrate.exe is wrapping the toolingfacade class So I created the object passing in the required variables as well as setting the verbosedelegate. The nice thing about this is that I could run the updatescript function instead if I just wanted to get the sql scripts

[Reflection.Assembly]::LoadFrom("EntityFramework.dll") | Out-Null
$con = New-Object -TypeName System.Data.Entity.Infrastructure.DbConnectionInfo -ArgumentList @("constring", "System.Data.SqlClient")
$tools = New-Object -TypeName System.Data.Entity.Migrations.Design.ToolingFacade -ArgumentList @("dbcondllname", "dbcondllname",$null,"workingdr",$null,$null,$con)
$tools.LogVerboseDelegate = {param($sql)
    Write-Verbose $sql -verbose #dumps the sql to RM log
}
$tools.Update($null,$false)
1
6/9/2018 6:07:41 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow