Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
EF Decode Migration History
void Main()
{
//DECLARE @binaryContent VARBINARY(MAX)
//SELECT @binaryContent = Model FROM[__MigrationHistory] where MigrationId = ''
//SELECT CAST('' AS XML).value('xs:base64Binary(sql:variable(''@binaryContent''))', 'varchar(max)') AS base64Content
var modelBase64 = "<base64Content>";
var bytes = Convert.FromBase64String(modelBase64);
var uncompressed = Decompress(bytes);
var edmx = Encoding.UTF8.GetString(uncompressed);
edmx.Dump();
}
static byte[] Decompress(byte[] gzip)
{
using (var stream = new GZipStream(new MemoryStream(gzip), CompressionMode.Decompress))
{
const int size = 4096;
var buffer = new byte[size];
using (var memory = new MemoryStream())
{
int count;
do
{
count = stream.Read(buffer, 0, size);
if (count > 0)
{
memory.Write(buffer, 0, count);
}
}
while (count > 0);
return memory.ToArray();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment