.net - EF 迁移 resx 文件中的目标字段采用哪种格式?

标签 .net entity-framework ef-code-first

使用 Entity Framework ,在以代码优先的方式使用迁移文件时,它会生成 .resx文件 (xml),其中包含名为 Target 的数据字段:

  <data name="Target" xml:space="preserve">
    <value>H4sIAAAAAAAEAO ... ICAA==</value>
  </data>

该字段是哪种格式? ==在数据的末尾使认为它是base64,但是当解码时,它看起来像是二进制数据。有人知道数据的结构/格式吗?

最佳答案

它是一个 edmx/xml 文件,已经被 gzipped 然后 base64 编码。以下应用程序将打印给定 .resx 文件的 xml。

using System;
using System.Collections;
using System.IO;
using System.IO.Compression;
using System.Resources;
using System.Xml.Linq;

namespace ResxReader
{
    class Program
    {
        private const string ResxFilename = @"full path to your .resx file";

        public static void Main()
        {
            var reader = new ResXResourceReader(ResxFilename);
            IDictionaryEnumerator resources = reader.GetEnumerator();

            while (resources.MoveNext())
            {
                if ("Target".Equals(resources.Key))
                {
                    XDocument target = Decompress(Convert.FromBase64String(resources.Value.ToString()));

                    Console.Write(target);
                }
            }
        }

        public static XDocument Decompress(byte[] bytes)
        {

            using (var memoryStream = new MemoryStream(bytes))
            {
                using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
                {
                    return XDocument.Load(gzipStream);
                }
            }
        }
    }
}

关于.net - EF 迁移 resx 文件中的目标字段采用哪种格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47768143/

相关文章:

c# - 将 EF 查询限制为具有 TPT 继承的基类型

sql-server - 我可以使用备份/恢复来移动使用 EF Code First 创建的数据库吗?

c# - 实体架构

.net - ASP.Net MVC 3 EF "Introducing FOREIGN KEY constraint on table may cause cycles or multiple cascade paths"

.net - 无法使用 azure Eventhub 在架构注册表中创建架构

c# - 我应该如何正确连接两个表,以便我可以访问其中一个实体中的属性?

c# - 跟踪同一应用程序的不同日志文件

c# - 我可以在 C# 5 和 .Net 4.5 中做哪些我在 C# 4 和 .Net 4 中不能做的事情?

entity-framework - 自跟踪实体 - 添加到集合时尝试插入未更改的实体

asp.net mvc 5 投票系统