【问题标题】:Problems with Schema XML attribute in EDMX fileEDMX 文件中的 Schema XML 属性问题
【发布时间】:2012-07-23 20:45:45
【问题描述】:

我正在使用从 EDMX 文件生成 POCO 的 T4 模板。

所有底层实体都有自己的架构。 That answer 描述了如何从 EDMX 中提取模式名称:

StoreItemCollection sic;
loader.TryCreateStoreItemCollection(inputFile, out sic);
EntityContainer sicEntityContainer = sic.GetItems<EntityContainer>().First();

EntitySet eset = sicEntityContainer.GetEntitySetByName(code.Escape(entity), true);
string schemaName = eset.MetadataProperties["Schema"].Value.ToString();

如果我查看一个 EDMX 文件的内容,我会发现每个实体都有一个 Schema 属性:

<EntitySet Name="Table_1"
           EntityType="TestModel.Store.Table_1"
           store:Type="Tables"
           Schema="Blubb" />

此时一切正常,我可以提取架构名称。

这就是问题所在:

自从一两个月以来,Visual Studio 2010 为我的模型中较新实体的 Schema 属性添加了一个名为 store 的前缀。

<EntitySet Name="Table_1"
           EntityType="TestModel.Store.Table_1"
           store:Type="Tables"
           store:Schema="Blubb" />

所以我无法使用上面链接文章的逻辑来提取模式。

我必须使用文本编辑器手动删除这些前缀,所以一切都可以正常工作。

我的问题:

  1. 这是什么原因?
  2. 我如何读取带有类似 store:Schema 的命名空间的属性?

【问题讨论】:

    标签: c# entity-framework t4 edmx edmx-designer


    【解决方案1】:

    您需要在“类型/架构”前面加上其命名空间

    即:

     eset.MetadataProperties["http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator:Type"].Value.ToString(); 
     eset.MetadataProperties["http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator:Schema"].Value.ToString(); 
    

    【讨论】:

    • 你的意思是“EntityStoreSchemaGenerator:Schema”代表“store:Schema”?
    【解决方案2】:

    不确定这是否会有所帮助,但可能会有所帮助,请参阅http://brewdawg.github.io/Tiraggo.Edmx/,您可以从 NuGet 安装它。它提供 edmx 文件中的所有元数据,包括所有映射、每列的低级 SQL 数据类型,所有这些东西,看看页面上的示例,你会发现它是多么容易。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      相关资源
      最近更新 更多