Created
October 30, 2014 08:00
-
-
Save JohannesHoppe/6f6cf025266e49fa20a7 to your computer and use it in GitHub Desktop.
Run this code if you want to review the current content of your [__MigrationHistory] table!
This file contains hidden or 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
using System.IO; | |
using System.IO.Compression; | |
using System.Text; | |
using NUnit.Framework; | |
using System; | |
namespace Example | |
{ | |
[TestFixture] | |
[Ignore("This is not a test. Run this code if you want to review the current content of your [__MigrationHistory] table!")] | |
public class DecodeMigrationHistory | |
{ | |
[Test] | |
public void Show_Current_Edmx() | |
{ | |
byte[] compressedModel = (byte[])Context.Execute(@"SELECT TOP 1 Model FROM [dbo].[__MigrationHistory] ORDER BY MigrationId DESC"); | |
byte[] uncompressed = DecompressGZip(compressedModel); | |
string edmx = Encoding.UTF8.GetString(uncompressed); | |
Console.WriteLine(edmx); | |
} | |
private static byte[] DecompressGZip(byte[] gzip) | |
{ | |
using (var stream = new GZipStream(new MemoryStream(gzip), CompressionMode.Decompress)) | |
{ | |
const int size = 4096; | |
byte[] 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