Skip to content

Instantly share code, notes, and snippets.

@rahulpnath
Created June 21, 2018 03:46
Show Gist options
  • Save rahulpnath/4e69bb4682ca5f42e8cf24cf3df25cbf to your computer and use it in GitHub Desktop.
Save rahulpnath/4e69bb4682ca5f42e8cf24cf3df25cbf to your computer and use it in GitHub Desktop.
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