EF 4.3 Code First Migrations - Uncompress __MigrationHistory Model

谁说胖子不能爱 提交于 2019-12-13 06:10:47

问题


How can I uncompress/read the compressed models stored in the EF 4.3 Code First Migrations __MigrationHistory table?

I found a hint in this comment, that I can uncompress it using zip/gzip, but I don't know how exactly I should do this.

The problem is that I have changed something in my ef model classes, but when I call "add-migration" an empty migration ist generated. I think that is because the changes of my model classes are already assigned to an existing migration :(


回答1:


(this may be a good starting point - won't work in your case)

I think you may find this useful - you 'just' need to work it out in the opposite direction, I think (I'm just hinting here as to what might be the direction, you'll have to check it out, test yourself)...

http://brice-lambson.blogspot.com/2012/05/using-entity-framework-code-first-with.html

It uses the following code...

private byte[] GetModel(TContext context)
{
    using (var memoryStream = new MemoryStream())
    {
        using (var gzipStream = new GZipStream(
            memoryStream,
            CompressionMode.Compress))
        using (var xmlWriter = XmlWriter.Create(
            gzipStream,
            new XmlWriterSettings { Indent = true }))
        {
            EdmxWriter.WriteEdmx(context, xmlWriter);
        }

        return memoryStream.ToArray();
    }
}  

to serialize the model.

However, as I understand (if I understand it properly) you need it in the other direction...

Quick search didn't show the equivalent reader - you can download the latest EF6 code - or also find EF5 one (I'll link in later if needed).

Reader:

Actually this may be closer to what you want:

http://edmxdom.codeplex.com/
(I haven't tried it out but was linked from MS)

http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/1546548f-9f90-4cc2-b1b2-28cf7e9d1cb5/

And check the response about using MetadataWorkspace

If you need more info on the MetadataWorkspace I'll post some posts I made on that subject. You can get most info out - you'll need to sort 'reverse' what EdmxWriter is doing.

Essentially, you're looking for entity framework Edmx reader.

EdmxDOM:

I just checked it out fast - and it seems to be doing the Edmx format management you need.
It's a 'VB' project - but you can work through that

There is what seems to be a 'reader' (again, not sure, just went through this, as I know about the writer - but never worked w/ this part, direction)...

Public Sub LoadFile(ByVal fileName As String)  

In the Edmx.vb



来源:https://stackoverflow.com/questions/15922984/ef-4-3-code-first-migrations-uncompress-migrationhistory-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!