Skip to content

Instantly share code, notes, and snippets.

@JohannesHoppe
Created October 30, 2014 08:00
Show Gist options
  • Save JohannesHoppe/6f6cf025266e49fa20a7 to your computer and use it in GitHub Desktop.
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!
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