从EDMX文件获取架构 [英] Getting the Schema from an EDMX file

查看:189
本文介绍了从EDMX文件获取架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要修改T4模板POCO.tt以从EDMX文件中检索数据库模式。我可以看到存储在XML中的EntitySet标签​​中的模式。但是我在使用EntitySet对象时无法找到模式。



任何人都知道我在哪里可以找到数据库模式?



谢谢

解决方案

更新
我在一份博客文章:



http://www.ninjanye.co.uk/2011/06/getting-schema-information-from-edmx.html



http://jnye.co/Posts/3/getting-schema-information-from-an-edmx-file-with-poco



I自己遇到了同样的问题。
首先,您需要从edmx文件的存储模型内容(edmx:StorageModels)部分中检索EntityContainer



在tt模板的顶部(之后) MetadataLoader被实例化并且声明了inputFile)添加以下代码以获取存储模型内容EntityContainer

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

然后从foreach(ItemCollection.GetItems ...)中的var实体循环中可以得到当前模式与以下

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

注意:您可能需要在tt模板中重复获取ComplexType属性的模式代码/ p>

I need to modify the T4 template POCO.tt to retrieve the database schema from the EDMX file. I can see the schema stored in an EntitySet tag in the XML. However I cannot find the schema anywhere when using an EntitySet object.

Anyone know where I would find the database schema?

Thanks

解决方案

UPDATE I wrote up my findings on this in a blog post:

http://www.ninjanye.co.uk/2011/06/getting-schema-information-from-edmx.html

http://jnye.co/Posts/3/getting-schema-information-from-an-edmx-file-with-poco

I came across this same problem myself. First you need to retrieve the EntityContainer from the Storage Model Content (edmx:StorageModels) section of the edmx file

At the top of the tt template (after the MetadataLoader is instantiated and the inputFile is declared) add the following code to get the Storage Model Content EntityContainer

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

Then from within the foreach (var entity in ItemCollection.GetItems...) loop you can get the current schema with the following

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

Note: You may have to repeat the get schema code for ComplexType properties lower down in the tt template

这篇关于从EDMX文件获取架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆