Created
June 21, 2018 03:46
-
-
Save rahulpnath/4e69bb4682ca5f42e8cf24cf3df25cbf to your computer and use it in GitHub Desktop.
EF Decode Migration History
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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